Search code examples
ruby-on-railssidekiq

sidekiq update parameters before retrying


How can I update an active job parameter before retrying? I have a job that needs some persistent storage so I store its data as an argument to the job (hash) and the data is updated after each job. If the job fails I want to retry with the updated data instead of the data that was used to schedule the job.

I am using sidekiq for scheduling my jobs btw.

Regards.


Solution

  • You need to rescue and create a new job with the modified parameter. Sidekiq does not allow you to modify a job from the Worker.

    def perform(a)
      begin
        do_work
      rescue SomeError
        self.class.perform_async(a+1)
      end
    end