Home > Web Front-end > JS Tutorial > Node.js node-schedule scheduled task execution method every few minutes_node.js

Node.js node-schedule scheduled task execution method every few minutes_node.js

WBOY
Release: 2016-05-16 16:14:48
Original
2167 people have browsed it

In Node.js, I use node-schedule to execute scheduled tasks. The Cron-style time format is not intuitive for beginners, so this method is generally used: For example, in the official example, the task is executed at 42 minutes per hour

Copy code The 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 to execute a task every 15 minutes or 30 minutes?

The key thing is that rule.minute supports arrays. Knowing this will make it easy to operate

Execute every 15 minutes:

Copy code The code is as follows:

rule.minute = [0, 15, 45];

Similarly, execute every 30 minutes:
Copy code The code is as follows:

rule.minute = [0, 30];
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template