Node.js Node-schedule How many minutes a scheduled task executes every minute _node.js

Source: Internet
Author: User

In Node.js, I use Node-schedule to perform timed tasks. Cron-style's time format is not intuitive for beginners, so it is generally used in this way: for example, the official example of 42 minutes per hour to perform the task

Copy Code code 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 do you perform a task every 15 minutes or 30 minutes?

The key point is that the rule.minute is supported by arrays, and knowing this is a good operation.

Perform every 15 minutes:

Copy Code code as follows:

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

Similarly, each 30-minute execution:
Copy Code code as follows:

Rule.minute = [0, 30];

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.