当用户在事件页面上设置事件时,我在react.js上有一个事件web应用程序,假设从今天起四天后,还有另一个setReminder下拉输入字段,其值是4小时前/3小时前,等等。
route/api/endpoint/postRequest post->api->userSchema->mongoDB->req.body -
json,{ setReminderTime: currentDateTime - req.body.data.setReminderValue }等,保存其他更多的数据,所以现在我想要我的代码在那里运行一个函数,我想在那里写一些代码--{减号}那个提醒日期/时间(4小时或3或2小时前),所以在提醒中我发送一个通知或一个smg,或者想做更多的事情,我不想每秒访问我的数据库,我也不想使用setTimeout staf再次因为puch->更新而再次使用服务器刷新。
发布于 2021-08-26 12:38:30
我不确定我是否已经很好地理解了您的问题,但是您可以尝试在服务器(后端)上使用一个提醒,并且您必须使用这样的cron服务来每小时运行提醒:
const schedulerFactory = function() {
return {
start: function() {
// this action will be executed every day at 12:00 u can choose what you wan't
new CronJob('00 00 12 * * *', function() {
//CronJob('0 */1 * * * *') // this for execute each one minute
console.log('Running Send Notifications Worker for ' + moment().format());
notificationsWorker.run(); // this should be the function to call and it will search for all instance where some condition are true and than execute them
}, null, true, '');
},
};
};在数据库中,您可以存储一些信息,以了解您是否必须执行此操作(例如,最后一次连接或类似的信息来知道何时发送通知)。
祝你好运兄弟。
https://stackoverflow.com/questions/68871475
复制相似问题