So I have a Sidekiq worker in my model which looks like this:
class Perk < ActiveRecord::Base
include Sidekiq::Worker
include Sidekiq::Status::Worker
after_save :update_release_time
def update_release_time
if self.release_time_changed?
#if scheduled job already exists then cancel and reschedule
# Sidekiq::Status.cancel scheduled_job_id
# scheduled_job_id = NotifierWorker.perform_at(time.seconds.from_now, .....)
#elsif scheduled job doesn't exist, then schedule for the first time
# scheduled_job_id = NotifierWorker.perform_at(time.seconds.from_now, .....)
#end
end
end
end
So basically, my code checks if the release time has changed. If it has, then it has to cancel the previously scheduled job and schedule it at a new time. How do I achieve this i.e what would go in place of my pseudo-code? How do I check if scheduled_job_id
exists and then fetch its id?
ScehduledSet
->ScheduledSet
– Muricate