简体   繁体   中英

Node.js: long delay

There is an event after which comes feedback on my server. I have to send a message to exactly one hour after the event.

I can use a setTimeout() but it seems it will not be good.

Perhaps it would be better if I start cron which will check the status of an event from database(such as every minute)

Does anyone know of a greater good option for the implementation of such a long delay?

If you require 100% reliability use a cron job. The problem with a cron job is that your code will be spread around the place and it would require configuration each time you set up a new server. An alternate approach would be to use an npm package like cron .

The issue with setTimeout() is that if your application crashes/restarts the future function call will be lost. However, each time your application starts, it could query the DB and see all missing timeouts and set them appropriately.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM