Search code examples
ruby-on-railssidekiq

Get enqueued_at inside scheduled Sidekiq job?


I have scheduled a job

Worker.perform_at(time, args)

When this job is eventually performed, is there a way to find out the original time that was scheduled?

Writing the question helped me come up with this solution, but I'm not sure if it works or if it is a good solution. Inside the worker:

this_job = Sidekiq::ScheduledSet.new.find_job(self.jid)
this_job.enqueued_at


Solution

  • If you want some data inside a Worker, you pass it in as an argument:

    Worker.perform_at(time, Time.now.to_f, *args)