Search code examples
ruby-on-railsrubyjobssidekiq

Sidekiq retry only in production environment


I have about a dozen sidekiq worker objects that are queued up periodically via the clockwork gem (roughly 10,000 jobs a day - not a ton). Everything is working great.

The issue is that while developing I'm prone to making mistakes in my code. If I leave the retry option out of the equation, those failed jobs will continue to try and try, flooding my development sidekiq logs with failures.

I want to know if I can either turn off retry in development mode or perhaps clear all jobs if I kill sidekiq locally (I'm thinking of the way database-cleaner works in testing). I've read over error handling but don't really see my topic covered.

for example:

class DailyActivityWorker
  include Sidekiq::Worker

  def perform(id)
    #make some call to an API
    #save parts of that call to the database
  end
end

I know I can add this inside every worker but that seems redundant

  sidekiq_options retry: false if Rails.env.development?

Is there a better way to go about this?


Solution

  • You should be able to set them in one place by modifying the default worker options:

    https://github.com/mperham/sidekiq/wiki/Advanced-Options#workers

    For example, config/initializers/sidekiq.rb:

    if Rails.env.development?
      Sidekiq.default_worker_options = { retry: false }
    end