In Node.js, I use node-schedule to perform timing tasks. The Cron-style time format is not very intuitive for beginners, so this method is generally used: for example, in the official example, the task is performed at 42 minutes per hour.
The code copy 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 to perform tasks every 15 minutes or 30 minutes?
The more critical thing is that rule.minute supports arrays, so it is easy to operate if you know this.
Perform every 15 minutes:
The code copy is as follows:
rule.minute = [0, 15, 45];
Similarly, every 30 minutes:
The code copy is as follows:
rule.minute = [0, 30];