如何使用PM2进行Cron工作 [英] How to make a cron job with PM2
本文介绍了如何使用PM2进行Cron工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做一份cron作业,每15分钟发送一次邮件,从数据库表中获取数据.在node js中,我可以执行cron作业,但是通过PM2,我不知道代码的放置位置和工作方式.
I want to make a cron job to send mail every 15 minutes taking data from a database table. In node js I can make a cron job but through PM2 I don't understand where to place the code and how it works.
推荐答案
感谢您的回答;我以这种方式做到了,只是设置了电子邮件
thank you for your answer; i do it in this way and just set the email
- npm install node-crontab
2. var crontab = require('node-crontab');
2. var crontab = require('node-crontab');
var jobId = crontab.scheduleJob("*/15 * * * *",function(){
var jobId = crontab.scheduleJob("*/15 * * * *", function(){
//This will call this function every 15 minutes
console.log("It's been 15 minutes!");
});
这篇关于如何使用PM2进行Cron工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文