Run Cron Job every 45 minutes with Node-Cron

前端 未结 8 758
别那么骄傲
别那么骄傲 2020-12-25 13:58

I\'m using node-cron to run scheduled jobs. I want the jobs to run every 45 minutes, but its acting strangely

Here\'s the pattern I\'m using

\'00 */45

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-25 14:27

    use cron npm moduel something like this

    var cronJob = require('cron').CronJob;  
    var job = new cronJob({ 
        cronTime:'0 */45 * * * *', 
        onTick: function(){
            var my_date = new Date();
            var tomorrow_date = my_date.getFullYear() + "-" + ('0'+(my_date.getMonth()+1)) + "-" + (my_date.getDate()+1)
            var condition = [{},{$set: {'plannedDeliveryDate' :tomorrow_date +'T00:00:00.000Z'}}]
            dbQuery.updateMany(orderModel, condition, function(err, result){
                if(result.nModified == result.n) console.log(err, result)
            })
        },
        start:true,
        timeZone:'Asia/Kolkata'
    });
    job.start();
    

提交回复
热议问题