loco
loco copied to clipboard
Cron/Scheduler support?
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);
...
Hey @exzachlyvv We are not supporting Cron or the scheduler. you can trigger the a task with your preferred operation
@exzachlyvv with rails, historically, there were 3 ways to run scheduled jobs:
- 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
- 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
- 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?
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 :)
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 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
I don't know wether it might help or not. But I use sidekiq-cron to support cron job when using Rails and Sidekiq
Hey @exzachlyvv, I just started to implement this feature: #735.
It will be great to get your feedback.
Released in version 0.9.0