Reputation: 300
I have implemented scheduled notifications using Sidekiq. I want to also add an ability of rescheduling jobs that haven't been run yet. I do see a reschedule method in the sidekiq api code https://github.com/mperham/sidekiq/blob/061068c551bd96eb6aa790dda0a4dad85bf55381/lib/sidekiq/api.rb but I am not sure what to pass as the arguments when initializing the SortedEntry class. There are no examples in the documentation so I was wondering if anybody has any experience with Sidekiq rescheduling? By the way I grab the jid when I create a job:
message_jid = MessagesWorker.perform_in(@message.deliver_at, msgs2_ids, @message.id)
Upvotes: 5
Views: 5237
Reputation: 22208
You do this:
Sidekiq::ScheduledSet.new.find_job(@message.jid).reschedule(1.day.from_now)
The find_job
call is very slow and will not scale to lots of jobs in the scheduled set. I recommend you either:
Upvotes: 8
Reputation: 300
Maybe there is a simpler way of rescheduling a message but I managed to do it somehow. My code:
scheduler = Sidekiq::ScheduledSet.new
job = scheduler.select {|s| s.klass == 'MessagesWorker' && s.jid == @message.jid }.first
entry = Sidekiq::SortedEntry.new(job.parent, job.score, job.item)
entry.reschedule(params[:message][:deliver_at])
Upvotes: 0