rails / solid_queue

Database-backed Active Job backend
MIT License
1.66k stars 90 forks source link

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

Open hms opened 2 months ago

hms commented 2 months ago

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.

rosa commented 1 month ago

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.