日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

nodejs定时任务node-schedule

發(fā)布時間:2024/4/14 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nodejs定时任务node-schedule 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1:使用npm安裝node-schedule模塊

npm install node-schedule

(1)每隔5分鐘執(zhí)行一次:

var schedule = require('node-schedule');var rule = new schedule.RecurrenceRule();rule.minute = [0,5,10,15,20,25,30,35,40,45,50,55];var j = schedule.scheduleJob(rule,function(){console.log("執(zhí)行任務(wù):"+new Date()); });

?(2)上午8點到晚上20點每隔5分鐘執(zhí)行一次:

var schedule = require('node-schedule');var rule = new schedule.RecurrenceRule();rule.hour = [8,9,10,11,12,13,14,15,16,17,18,19,20]; rule.minute = [0,5,10,15,20,25,30,35,40,45,50,55];var j = schedule.scheduleJob(rule,function(){console.log("執(zhí)行任務(wù):"+new Date()); });

?

2:以下內(nèi)容參考:

http://www.codexpedia.com/javascript/nodejs-cron-schedule-examples/

Using the node-schedule to schedule a job to run at a specific time on a specific date. As the first example, the node-schedule module is imported and save it in the variable cron. In the following examle, the require statement will be ommitted and this variable cron will be used.

1 2 3 4 5 6 var cron = require('node-schedule'); /* run the job at 18:55:30 on Dec. 14 2018*/ var date = new Date(2018, 11, 14, 18, 56, 30); cron.scheduleJob(date, function(){ ????console.log(new Date(), "The world is going to end today.");??? });

?

Schedule a recurring job using the RecurrenceRule, example 1.

1 2 3 4 5 var rule = new cron.RecurrenceRule(); rule.second = 30; cron.scheduleJob(rule, function(){ ????console.log(new Date(), 'The 30th second of the minute.'); });

?

Schedule a recurring job using the RecurrenceRule, example 2.

1 2 3 4 5 6 7 8 /* This runs at 3:10AM every Friday, Saturday and Sunday. */ var rule2 = new cron.RecurrenceRule(); rule2.dayOfWeek = [5,6,0]; rule2.hour = 3; rule2.minute = 10; cron.scheduleJob(rule2, function(){ ????console.log('This runs at 3:10AM every Friday, Saturday and Sunday.'); });

?

Specify the schedule as an object literal.

1 2 3 4 /* This runs at 2:30AM on every Sunday */ cron.scheduleJob({hour: 2, minute: 30, dayOfWeek: 0}, function(){ ????console.log('This runs at 2:30AM on every Sunday'); });

?

Specify the schedule in unix cron syntax.

1 2 3 4 /* This runs at the 30th mintue of every hour. */ cron.scheduleJob('30 * * * * *', function(){ ????console.log('This runs at the 30th mintue of every hour.'); });

轉(zhuǎn)載于:https://www.cnblogs.com/yshyee/p/4465741.html

總結(jié)

以上是生活随笔為你收集整理的nodejs定时任务node-schedule的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。