我使用node-schedule,在周末发送一条通知,由于某种原因,即使我明确禁止其发送重复通知,也会发出重复通知
cron.schedule('0 5 23 * * 7', someFunction); is what I call.
someFunction如下:
module.exports = async () => {
const users = await User.find({ isSpecialUser: true });
users.forEach(async user => {
const notifications = await Notification.find({ to: user._id, read: false });
const duplicated = notifications.find(notification =>
momnet(notification.createdAt).format('YYYY/MM/DDD') === momnet().format('YYYY/MM/DDD'));
if(!duplicated) {
await notificationManager.notify(user._id,
'Reminder', 'sendsomenotification');
}
});
};
我认为cron编写正确,但不确定为什么调用此调度程序两次并且用户看到两个通知。这是服务器端问题吗?