Node. js node-schedule
In Node. js, I use node-schedule to execute scheduled tasks. The time format of Cron-style is not intuitive for beginners, so this method is generally used: for example, the official example shows how to execute a task at 42 points per hour.
Copy codeThe Code is as follows:
Var schedule = require ('node-schedule ');
Var rule = new schedule. RecurrenceRule ();
Rule. minute = 42;
Var j = schedule. scheduleJob (rule, function (){
Console. log ('The answer to life, The universe, and everything! ');
});
So the question is, how can we execute a task every 15 minutes or 30 minutes?
The most important thing is that rule. minute supports arrays, which is a good operation.
Run the following command every 15 minutes:
Copy codeThe Code is as follows:
Rule. minute = [0, 15, 45];
Similarly, run the following command every 30 minutes:
Copy codeThe Code is as follows:
Rule. minute = [0, 30];