简体   繁体   English

在节点js中为日期范围设置cron作业

[英]setting cron jobs in node js for date range

I am working on a project where I need to send emails on the date which is in between two selected dates along with specific week days like only Monday and Thursday 我正在一个项目中,我需要在两个选定日期之间的日期以及特定的工作日(例如仅星期一和星期四)之间发送电子邮件

The cron syntax is: cron语法为:

0 * * * * * 0 * * * * *

And the allowed values should be between below options 并且允许的值应该在以下选项之间

  1. Seconds: 0-59 秒:0-59
  2. Minutes: 0-59 分钟:0-59
  3. Hours: 0-23 时间:0-23
  4. Day of Month: 1-31 每月的日期:1-31
  5. Months: 0-11 月:0-11
  6. Day of Week: 0-6 星期几:0-6

I tried using node-schedule - npm . 我尝试使用node-schedule -npm See my code below 请参阅下面的代码

var j = schedule.scheduleJob({ start: obj.start_date, end: obj.end_date, dayOfWeek: obj.dayOfWeek, hour: obj.hour, minute: obj.minute, second: 1 }, function(params){
         console.log(params);
    }.bind(null, obj));

I am able to run the jobs on dates but its not persistent. 我可以按日期运行作业,但不是永久的。 Whenever I make changes and starts the server it resets the scheduled jobs. 每当我进行更改并启动服务器时,它都会重置计划的作业。

So how can I set a cron job which will run for specific dates(or date range) on selected days(Monday, tuesday etc)? 那么,如何设置将在选定日期(星期一,星期二等)的特定日期(或日期范围)运行的Cron作业?

I got the work around on this. 我已经解决了这个问题。 As I stored cron jobs in cache and whenever the server restarts, pushed them in to the cron again. 当我将cron作业存储在缓存中并且每当服务器重新启动时,将它们再次推入cron。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM