Search code examples
ruby-on-railsrubysidekiq

retrieve the scheduled date of a sidekiq worker within it


Let's have a lot of jobs queued for a certain Date my_date.

There is so much job for this exact same date that some of them are working only 20 minutes after their scheduled_date.

How can I retrieve this scheduled date once I am in my perform method ?

ps : I can't pass this scheduled_date as params, because its a Cron job (and I can only pass static params)

ps2 : github issue https://github.com/mperham/sidekiq/issues/3945

edit : for now here is a partial answer, still not satisfying (for exemple not working for a retry):

# wait for Sidekiq::Workers to be updated (5 sec)
sleep 8
the_exact_date = Time.at(Sidekiq::Workers.new.find { |_, __, w| w["payload"]["jid"] == jid }[2]["run_at"])

edit 2 : current PR for sidekiq cron which fully solve my issue : https://github.com/ondrejbartas/sidekiq-cron/pulls


Solution

  • if you are using Sidekiq-cron :

    I submitted a PR and it was accepted. The solution is to use the optional date_as_argument param when initializing your sidekiq-cron job:

    https://github.com/ondrejbartas/sidekiq-cron#getting-started