Node. js node-schedule

Source: Internet
Author: User

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];

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.