Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hms opened this issue May 16, 2024 · 2 comments

Comments

@hms
Copy link
Contributor

hms commented May 16, 2024

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
Copy link
Member

rosa commented May 28, 2024

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.

@iJackUA
Copy link

iJackUA commented Oct 17, 2024

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants