Closed Xstoudi closed 3 years ago
@Xstoudi Thanks a lot for creating the RFC. Appreciate it. There are some key details missing right now. So let's work towards completing them.
There are a few more doubts, but I believe, we should first try to get answers to these
Another point to consider: one may want to execute the scheduled task in a sub-process or in a worker because it may be CPU-intensive.
Cron is a UNIX-specific program. I don't think we should rely on it. Scheduled tasks should be handled by Node.js via Adonis. About the consideration of multiples processes : the simplest way for us to implement it is 10 process = task ran 10 times. What do you think about it?
I agree with @targos and furthermore I'd say Task are always child processes.
Another quick question
the simplest way for us to implement it is 10 process = task ran 10 times
Yes, the simplest approach. But maybe not the expected approach. Infact, I was looking at the Laravel docs https://laravel.com/docs/7.x/scheduling#running-tasks-on-one-server and they indeed prevent a task from running onto multiple servers. I would expect that too from a well designed scheduler
If we want a complete scheduler, we surely needs a multi-driver storage options. For status tracing as well as for 10 process = task ran 1 single time.
Yup. That's the plan. If we are planning to add a feature, then it should be mature enough to handle commonly known scenarios.
We can use the node-cron
package: https://github.com/kelektiv/node-cron
Any updated regarding Scheduled tasks?
Brief history
Scheduling tasks is probably as old as computers : cron is 45 years old. I don't think I need to write more about it.
What problem does it solve?
Today, the way I schedule tasks on Adonis is the following : I open an SSH command line and create a cron task that execute an ace command (
node ace mytask
in example).The main problem is that I can't version control task scheduling as I need to edit them manually on the server.
Proposal
I'll propose two ways to implement it, don't hesitate to be sceptical about it and to provide other ideas.
Task are classes
We can easily imagine that the command
node ace make:schedule Archive
would create the following file inapp/Tasks/ArchiveTask.ts
:Then when Adonis boots, it begin to check which time it is and run the ArchiveTask's run method when it is 00:00 on every 1st day of the month.
Schedule variable is crontab format:
Tasks are scheduled Commands
The other way to think about it is to imagine an optional field on BaseCommand that allow the user to pass crontab format. Again, Adonis then check what he needs to execute at the current time. Exemple:
Relevant links
CRON Scheduling in Laravel
Are you willing to work on it?
Yeah, with some little guidance.