简体   繁体   中英

Sidekiq not connecting to Rails

I am having issues converting from Resque to Sidekiq. I'm not getting any errors though a perform_async(ids) doesn't add anything to 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. I don't know if this matters but Sidekiq.redis { |conn| conn.info } Sidekiq.redis { |conn| conn.info } returns information that is all correct with my local Redis server. Though Sidekiq.server? returns a nil value.

Update: When I perform a perform_async(args) it returns a string.

It sounds like your Sidekiq configuration isn't using the same redis config for the client and server components of Sidekiq.

The client executes within your Rails app server, while the server is a stand-alone separate process where work is performed. If they both aren't using the same redis queue via the redis configuration, work will not be processed.

Here is an example config/initializers/sidekiq.rb config block using the same redis for both components:

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.

The solution was amending my Gemfile as such:

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

Finally, I added require 'rspec-sidekiq' in my spec_helper.rb .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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