3

We are rolling out a new app with Sidekiq and Rails 5. We are leveraging Redis for storing jobs but for some reason both locally and on our dev zone the jobs don't seem to be passing into Redis.

When the code executes on its own as well as via IRB the Notification seems to be properly sent.

[10] pry(main)> Notifications::WelcomeWorker.perform_async(1)
=> "1a1447c488f173fb09b212f7"

Looking into Redis we have keys for failed and processed (both say 0) but nothing for pending which makes me believe it is not even hitting Redis for some reason.

Our Redis config is setup in config/sidekiq.yml which simply sets concurrency and the PID location.

We have an initializer file as well in initializers/sidekiq.rb

Sidekiq.configure_server do |config|
  config.redis = { url: ENV["SIDEKIQ_REDIS"] , namespace: 'abcbh', network_timeout: 5  }
end
Sidekiq.configure_client do |config|
  config.redis = { url: ENV["SIDEKIQ_REDIS"] , namespace: 'abcbh', network_timeout: 5  }
end

SIDEKIQ_REDIS translates to redis://localhost locally and the relevant URL on dev.

Everything seems to work fine and yet the jobs do not seem to appear in Redis.

Is there something I am missing in my sleep deprivation?

The worker itself is setup in app/workers/notifications/welcome_worker.rb

In app/workers/notifications/welcome_worker.rb we have the following code though it never gets executed.

require 'sendgrid-ruby'
include SendGrid
class Notifications::WelcomeWorker
  include Sidekiq::Worker

  sidekiq_retries_exhausted do |msg, e|
    Sidekiq.logger.warn "Failed #{msg['class']} with #{msg['args']}: #{msg['error_message']}"
  end

  def perform(email_id)
    Sidekiq.logger.info "Beginning Welcome Email For #{email_id}"
    ...
  end
end
CogitoErgoSum
  • 2,879
  • 5
  • 32
  • 45
  • 1
    Did you start sidekiq in the environment? – Mark Jan 05 '17 at 18:16
  • Yes. Two terminal windows open on my local one running bin/rails -c for my IRB and a second that executes bundle exec sidekiq -c config/sidekiq.yml – CogitoErgoSum Jan 05 '17 at 18:37
  • 1
    Did you specify the `RAILS_ENV`? I once had a similar problem but simply over read that sidekiq will not run on `development` environment (a few versions ago - don't know if this is default behavior). Have you looked at the `sidekiq.log` for any errors? Other problem might be the log level... that is to low to show up depending on your configuration. – Mark Jan 05 '17 at 18:42
  • Upvoting this as it was related to the issue. My answer clarifies this but the reason it won't run on development is because of rspec-sidekiq. I'm still trying to understand the reasoning though. It doesn't seem well documented at all. – CogitoErgoSum Jan 05 '17 at 18:51

1 Answers1

4

After additional Google-fu I found the issue already reported

Sidekiq worker not getting triggered - Please upvote this question and answer if you have come here for the same probelm. They deserve it more!

TL:DR - rspec-sidekiq gem should be in test only. Apparently this screws with development.

I will now go bang my head against a wall and wonder why my google-fu failed me for two days straight.

Community
  • 1
  • 1
CogitoErgoSum
  • 2,879
  • 5
  • 32
  • 45
  • Sounds like the problem I once had. But I couldn't remember the solution! You are not the only one that has been fooled by this :) – Mark Jan 05 '17 at 18:49