I'm creating Elasticsearch callbacks using Sidekiq. I started Redis and Sidekiq, and created an object in rails console but it seems like perform_sync
is not firing. If I add require 'sidekiq/testing';Sidekiq::Testing.inline!
to sidekiq.rb
, it logs and raises an error as I expect though. Am I missing something?
Ruby 2.3.0
Rails 5.0.2
Sidekiq 4.2.9
Redis 3.2.0
sidekiq.rb
REDIS_URL = 'localhost'
REDIS_PORT = '6379'
Sidekiq.configure_server do |config|
config.redis = { url: "redis://#{REDIS_URL}:#{REDIS_PORT}" }
end
Sidekiq.configure_client do |config|
config.redis = { url: "redis://#{REDIS_URL}:#{REDIS_PORT}" }
end
indexable.rb
module Indexable
extend ActiveSupport::Concern
included do
def index_elasticsearch
Rails.logger.debug 'call'
Rails.logger.debug Indexer::Logger
Rails.logger.debug Indexer::Client
Rails.logger.debug self.id.to_s
Indexer.perform_async(:index, self.id.to_s) # nothing happens here
Rails.logger.debug 'after'
self
end
end
class Indexer
include Sidekiq::Worker
sidekiq_options queue: :elasticsearch, retry: false, backtrace: true
Logger = Sidekiq.logger.level = Logger::DEBUG ? Sidekiq.logger : nil
raise 'No config/elasticsearch.yml' unless File.exists? "config/elasticsearch.yml"
erb = ERB.new( File.read('config/elasticsearch.yml') ).result
config = YAML.load(erb)[Rails.env].symbolize_keys
config.merge! logger: Logger
Client = Elasticsearch::Client.new(config)
def perform(operation, record_id)
Rails.logger.debug [ operation, "ID: #{record_id}"]
raise
end
end
end
some_mongoid_class.rb
class SomeMongoidClass
...
include ::Indexable
...
after_save :index_elasticsearch
end
console
bundle exec sidekiq -e development --queue elasticsearch --verbose
...Booting Sidekiq 4.2.9 with redis options {:url=>"redis://localhost:6379"}...
2017-11-10T ... DEBUG: {:queues=>["elasticsearch"], :labels=>[], :concurrency=>25, :require=>".", :environment=>"development", :timeout=>8, ...
rails console
SomeMongoidClass.create(...)
before
#<Logger:0x...
#<Elasticsearch::Transport::Client:0x...
BSON::ObjectId('...')
after