[英]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. 我可以使用
setTimeout()
但似乎效果不好。
Perhaps it would be better if I start cron
which will check the status of an event from database(such as every minute) 也许如果我启动
cron
会更好,它将检查数据库中事件的状态(例如每分钟)
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. 如果您需要100%的可靠性,请使用cron作业。 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.
cron作业的问题是您的代码将散布在各处,并且每次安装新服务器时都需要进行配置。 An alternate approach would be to use an npm package like cron .
另一种方法是使用像cron这样的npm软件包。
The issue with setTimeout()
is that if your application crashes/restarts the future function call will be lost. setTimeout()
的问题在于,如果您的应用程序崩溃/重新启动,则将来的函数调用将丢失。 However, each time your application starts, it could query the DB and see all missing timeouts and set them appropriately. 但是,每次您的应用程序启动时,它都可以查询数据库并查看所有丢失的超时并进行适当设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.