sina
sina

Reputation: 980

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

Upvotes: 3

Views: 784

Answers (1)

matanco
matanco

Reputation: 2129

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.

Upvotes: 4

Related Questions