Search code examples
ruby-on-railssidekiq

Update args of a scheduled job


I have scheduled a job

Worker.perform_at(time, args)

And I can fetch the scheduled jobs

job = Sidekiq::ScheduledSet.new.find_job(jid)
job.args # this is the args I passed above

I need to update the args that will be passed to the worker when it is called, i.e. update job.args. How do I do that?

This won't work:

job.args = new_args
Sidekiq::ScheduledSet.new.to_a[0] = job

Solution

  • Well update the task is not the way achieving it cancel job and create new with new args:

    job = Sidekiq::ScheduledSet.new.find_job(jid)
    ## time = job.time // Or just set time needed.
    Sidekiq::Status.cancel jid
    
    Worker.perform_at(time, new_args) 
    

    it will also make it easier for you to debug and log the jobs because when you edit/update them on the fly could cause bugs that very hard to identify.