Search code examples
redissidekiq

Sidekiq - Reschedule failed job


I have a background job using Sidekiq connecting to another service of mine like this:

  def perform(id)
      user = ABCClient.instance.user(id)
      ...
  end

Sometimes this ABCClient is down and I would like to reschedule the "perform" job in this case. Like this:

  def perform(id)
      begin
          user = ABCClient.instance.user(id)
      rescue => e
          # Reschedule job
      end
      ...
  end

Solution

  • https://github.com/mperham/sidekiq/wiki/Scheduled-Jobs

    rescue => e self.class.perform_in(5.minutes, id) end