loco icon indicating copy to clipboard operation
loco copied to clipboard

Cron/Scheduler support?

Open exzachlyvv opened this issue 10 months ago • 6 comments

First off, THANK YOU for loco.rs :)

I've been looking for a Rails/Laravel equivalent in Rust for a while.

Is there a plan to add a cron/scheduler system?

Laravels API is incredible and could be inspired.

...some scheduler somewhere...

scheduler.every_minute(MyTaskToRunEveryMinute);
scheduler.hourly(MyTaskToRunEveryHour);
...

exzachlyvv avatar Apr 10 '24 03:04 exzachlyvv

Hey @exzachlyvv We are not supporting Cron or the scheduler. you can trigger the a task with your preferred operation

kaplanelad avatar Apr 10 '24 06:04 kaplanelad

@exzachlyvv with rails, historically, there were 3 ways to run scheduled jobs:

  1. always-on daemon, that keeps a schedule as well. usually there was special care for expressing a schedule in plain english.
schedule "every 2 weeks" do 
  # some code
end
  1. Creating a watchdog / task that "wakes up", checks if there are tasks to run, and runs all pending tasks per schedule. Usually this "watchdog" task was run every 5 minutes with Cron. This also means maintaining state ("what are the tasks that should run next?") persisted somewhere
  2. Having a queue with delayed job, where the delayed job worker is run periodically like (2) every constant time window.

Which technique would you be referring to?

jondot avatar Apr 10 '24 09:04 jondot

Any of these would work :)

My use case is simply that I need to run some code every X minutes. There are no requirements for a specific API.

Is this functionally Loco is interested in supporting (happy to help with it)? If yes, we can continue to discuss the ideal design for loco.

Simple idea: expose some endpoint /run-my-task and have an external service ping it every X minutes.

But ideally Loco can solve this problem :)

exzachlyvv avatar Apr 10 '24 15:04 exzachlyvv

Loco depends on sidekiq-rs which support Periodic Jobs. Maybe loco can expose the worker process in hooks(something like after_boot?) to support this?

ShallmentMo avatar Apr 16 '24 11:04 ShallmentMo

@ShallmentMo that's a great idea. I'm wondering how to integrate that seamlessly. On the face of it it looks like a "forever-running" await and so it needs a dedicated thread or process. So, if we create a Loco task and tell the user: "run this task in any way you like, it will hang and run the periodic jobs" it might work. On the other hand it will be 1 more extra process. I'd welcome more ideas to satisfy: minimum user friction, and minimum resources neeed

jondot avatar Apr 16 '24 12:04 jondot

I don't know wether it might help or not. But I use sidekiq-cron to support cron job when using Rails and Sidekiq

ShallmentMo avatar Apr 16 '24 15:04 ShallmentMo

Hey @exzachlyvv, I just started to implement this feature: #735.

It will be great to get your feedback.

kaplanelad avatar Sep 05 '24 06:09 kaplanelad

Released in version 0.9.0

kaplanelad avatar Sep 19 '24 08:09 kaplanelad