admin管理员组文章数量:1332694
In our express js application have a feature in admin module that he can send mail to users at specific dates (he can able to select a specific date and time).
Say if the date and time is [email protected] we need to run the email code at that time.
I think this package will full fill our needs ,
Here is their documentation
* * * * * *
┬ ┬ ┬ ┬ ┬ ┬
│ │ │ │ │ │
│ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun)
│ │ │ │ └───── month (1 - 12)
│ │ │ └────────── day of month (1 - 31)
│ │ └─────────────── hour (0 - 23)
│ └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)
But it doesn't say how to run on specific date (year field is missing??) so how do i achieve my need?
In our express js application have a feature in admin module that he can send mail to users at specific dates (he can able to select a specific date and time).
Say if the date and time is [email protected] we need to run the email code at that time.
I think this package will full fill our needs https://www.npmjs./package/node-schedule,
Here is their documentation
* * * * * *
┬ ┬ ┬ ┬ ┬ ┬
│ │ │ │ │ │
│ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun)
│ │ │ │ └───── month (1 - 12)
│ │ │ └────────── day of month (1 - 31)
│ │ └─────────────── hour (0 - 23)
│ └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)
But it doesn't say how to run on specific date (year field is missing??) so how do i achieve my need?
Share Improve this question asked Jan 16, 2018 at 4:55 shamon shamsudeenshamon shamsudeen 5,85820 gold badges74 silver badges144 bronze badges2 Answers
Reset to default 3for specific date, you could use something like following as provided in example
var schedule = require('node-schedule');
var date = new Date(2018, 1, 22, 12, 0, 0);
var j = schedule.scheduleJob(date, function(){
console.log('job is running');
});
You can pass date object in it. if you read document further you will find it here : https://www.npmjs./package/node-schedule#date-based-scheduling
var schedule = require('node-schedule');
var date = new Date(2012, 11, 21, 5, 30, 0);
var j = schedule.scheduleJob(date, function(){
console.log('The world is going to end today.');
});
本文标签: javascriptRunning cron job at only specific date and timeStack Overflow
版权声明:本文标题:javascript - Running cron job at only specific date and time - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742341108a2456621.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论