网站建设方案书应急处置方案,科技创新的评价机制的作用,珠海网站建设制作,php网站开发if的代码概述
工作中有个需求#xff1a;在特定的时间发送一些消息#xff0c;也就是说比如在每天的7点发送消息#xff1a;该起床了。一开始我想用定时器每分钟每分钟的去查当前时间#xff0c;但好像有点蠢#xff0c;然后我找到了这个包
使用方法
安装
npm install node-sc…概述
工作中有个需求在特定的时间发送一些消息也就是说比如在每天的7点发送消息该起床了。一开始我想用定时器每分钟每分钟的去查当前时间但好像有点蠢然后我找到了这个包
使用方法
安装
npm install node-schedule使用
const schedule require(node-schedule);schedule.scheduleJob(* * * * * *, function () {console.log(111111);
});这里的每个*都可以被换掉比如你要每个整点都执行一次这段你就写成 0 * * * * 可以有缺省默认缺省的都在最左边秒 分 时 天 月 年
判断工作日
这里我采用的是chinese-workday来判断是否是工作日使用方法参考
const schedule require(node-schedule);
const ww require(chinese-workday);
const sendMessage require(../util/sendMessage);
const sys_user require(../db/model/sys_user);module.exports.msgReminder async () {let users await sys_user.findAll({ raw: true });schedule.scheduleJob(00 19 * * *, async function () {if (ww.isWorkday(new Date())) {for (let user of users) {let msg 提醒一下要xxxxxx了; sendMessage(msg, user.open_id);}}});
};