Sidekiq to cancel the list of scheduled tasks

I have several scheduled tasks that work as follows:

MyWorker.perform_at(3.hours.from_now, 'mike', 1) 

I wonder if later, say, in an hour, I feel that I want to cancel this work, how would I do it?

+12
ruby sidekiq
Apr 15 '13 at 7:16
source share
2 answers

I recently wrote some code to handle this, it is available in my sidekiq-status attribute branch. You can view it or use it here: https://github.com/Robinson7D/sidekiq-status

(You should use this as git: information git: in the gemfile, for now, until the main project fork implements this)

To use it, you first save the job_identifier identifier:

 job_identifier = MyWorker.perform_at(3.hours.from_now, 'mike', 1) 

And when you want to destroy it, you call the Sidekiq :: Status.cancel method:

 Sidekiq::Status.cancel job_identifier 

Edit: since writing this post, my code has been accepted in the Sidekiq :: Status main fork - https://github.com/utgarda/sidekiq-status . You no longer need to use your plug. On Utgard’s fork, you will call him, calling inhumanly, instead of canceling:

 Sidekiq::Status.unschedule job_identifier 

Next: you can also delete tasks using the standard Sidekiq stone, as described here: https://github.com/mperham/sidekiq/wiki/API (although for their methods you need unix-timestamp when the task is scheduled - you cannot delete only with the task ID, if you want to delete the task without a time stamp, the Sidekiq :: Status method may be right for you).

However, instead of what they describe in the wiki, I would recommend something along the lines of Sidekiq::ScheduledSet.new().delete(unix_timestamp, jid) if you want to delete only one job.)

+15
Jul 26 '13 at 1:17
source share

As far as I know, Sidekiq has no way to cancel the schedule at the moment. Because of this, I wrote a service that allows me to cancel scheduled emails. But you rarely complete tasks with redis commands:

You get scheduled tasks as follows:

 schedules_jobs = $redis.zrange "schedule", 0, -1, {withscores: true} 

Then you get an array of tasks, and you select one task and cancel it as follows:

 $redis.zrem "schedule", schedules_jobs[0] 
+3
May 13 '13 at 16:11
source share



All Articles