简体   繁体   English

Sidekiq未连接到Rails

[英]Sidekiq not connecting to Rails

I am having issues converting from Resque to Sidekiq. 我在从Resque转换到Sidekiq时遇到问题。 I'm not getting any errors though a perform_async(ids) doesn't add anything to Redis. 尽管perform_async(ids)不会向Redis添加任何内容,但我没有任何错误。 I can add keys directly to the Redis server via the Redis.current.append("test", "key") Also my Sidekiq worker connects to the Redis server, though I get an empty array when I ask for Sidekiq::Client.registered_workers The web UI shows only the skeleton with no information other than the Redis info. 我可以通过Redis.current.append("test", "key")将密钥直接添加到Redis服务器。我的Sidekiq工作程序也连接到Redis服务器,尽管当我请求Sidekiq::Client.registered_workers时得到一个空数组Sidekiq::Client.registered_workers Web UI仅显示框架,除了Redis信息外没有其他信息。 I don't know if this matters but Sidekiq.redis { |conn| conn.info } 我不知道这是否重要,但是Sidekiq.redis { |conn| conn.info } Sidekiq.redis { |conn| conn.info } returns information that is all correct with my local Redis server. Sidekiq.redis { |conn| conn.info }返回的信息对于我的本地Redis服务器都是正确的。 Though Sidekiq.server? 虽然Sidekiq.server? returns a nil value. 返回nil值。

Update: When I perform a perform_async(args) it returns a string. 更新:当我执行perform_async(args)它返回一个字符串。

It sounds like your Sidekiq configuration isn't using the same redis config for the client and server components of Sidekiq. 听起来您的Sidekiq配置没有为Sidekiq的客户端和服务器组件使用相同的redis配置。

The client executes within your Rails app server, while the server is a stand-alone separate process where work is performed. 客户端在您的Rails应用服务器中执行,而服务器是一个独立的独立进程,在其中执行工作。 If they both aren't using the same redis queue via the redis configuration, work will not be processed. 如果他们都没有通过Redis配置使用相同的Redis队列,则不会处理工作。

Here is an example config/initializers/sidekiq.rb config block using the same redis for both components: 这是一个示例config/initializers/sidekiq.rb配置块,两个组件使用相同的redis:

redis = { url: (ENV['REDIS_URL'] || 'redis://127.0.0.1'), namespace: 'sidekiq' }

Sidekiq.configure_server do |config|
  config.redis = redis
end

Sidekiq.configure_client do |config|
  config.redis = redis
end

My guess is that you have a different namespace or configuration between your client and server config. 我的猜测是,客户端和服务器配置之间的名称空间或配置不同。

I was hitting the same issue. 我遇到了同样的问题。

Turns out I had rspec-sidekiq configured in my Gemfile 's development group and rspec-sidekiq apparently stubs the async calls for testing. 原来,我在Gemfiledevelopment组中配置了rspec-sidekiq ,并且rspec-sidekiq显然对异步调用进行了测试。

The solution was amending my Gemfile as such: 解决方案是这样修改我的Gemfile

gem 'rspec-sidekiq', group: :test, require: false

Finally, I added require 'rspec-sidekiq' in my spec_helper.rb . 最后,我在spec_helper.rb中添加了spec_helper.rb require 'rspec-sidekiq'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM