gpt4 book ai didi

ruby-on-rails - Sidekiq perform_async 未触发

转载 作者:可可西里 更新时间:2023-11-01 11:25:01 25 4
gpt4 key购买 nike

我正在使用 Sidekiq 创建 Elasticsearch 回调。我启动了 Redis 和 Sidekiq,并在 Rails 控制台中创建了一个对象,但似乎 perform_sync 没有触发。如果我将 require 'sidekiq/testing';Sidekiq::Testing.inline! 添加到 sidekiq.rb,它会按照我的预期记录并引发错误。我错过了什么吗?

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

可索引.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

最佳答案

我发布最后一条评论后,这个问题就解决了。

这只是一个愚蠢的错误。我没有把worker文件放到app的workers文件夹里!

关于ruby-on-rails - Sidekiq perform_async 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47221822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com