Sidekiq perform_async未触发

问题描述 投票:0回答:1

我正在使用Sidekiq创建Elasticsearch回调。我启动了Redis和Sidekiq,并在rails控制台中创建了一个对象,但是perform_sync似乎没有触发。如果我将require 'sidekiq/testing';Sidekiq::Testing.inline!添加到sidekiq.rb,它会记录并按照我的期望引发错误。我想念什么吗?Ruby 2.3.0Rails 5.0.2Sidekiq 4.2.9Redis 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

控制台

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控制台

SomeMongoidClass.create(...)

before
#<Logger:0x...
#<Elasticsearch::Transport::Client:0x...
BSON::ObjectId('...')
after
ruby-on-rails elasticsearch redis mongoid sidekiq
1个回答
0
投票

我发布最新评论后,此问题已解决。

这只是一个愚蠢的错误。我没有将工作程序文件放入应用程序的工作程序文件夹中!

© www.soinside.com 2019 - 2024. All rights reserved.