solid_queue icon indicating copy to clipboard operation
solid_queue copied to clipboard

Question: What is the right way to initiate a cron job once at boot and then on the cron schedule?

Open hms opened this issue 1 year ago • 1 comments

I have several cron jobs. Because I'm currently locked to Heroku, there are times when I'm not in control of when my application is running or gets restarted. To that end, in the case of missing the window for a daily / periodic Cron execution, I use a Rails.application.after_initialization block to run these jobs once at SolidQueue boot.

Is this the right way / Is there a better way?

Thanks in advance.

hms avatar May 16 '24 19:05 hms

Hmm... I never had this need so I'm not completely sure, but that sounds right to me. Maybe this could be a future enhancement: on start, check if the last run of every recurring task happened, and if not, enqueue one 🤔 Though it'd be a little brittle, depending on how often restarts happen and your preservation period for finished jobs.

rosa avatar May 28 '24 09:05 rosa

Found this issue searching for first_in replacement While migrating from Sidekiq + Sidekiq-Scheduler (https://github.com/sidekiq-scheduler/sidekiq-scheduler) I was using smth like

# sidekiq.yml

do_the_job:
      class: MyJob
      every: ["30s", first_in: "0s"]
      args: ["one"]
      queue: default

so it runs every 30s and starts immediately after the app start, maybe SolidQueue's recurring.yml grammar can be extended to smth like this

  do_the_job:
      class: MyJob
      queue: default
      schedule: every 30s
      first_run_in: 0s

and accept values supported by Fugit::Duration https://github.com/floraison/fugit?tab=readme-ov-file#fugitduration ?

iJackUA avatar Oct 17 '24 18:10 iJackUA