简体   繁体   English

我如何运行以暂停我的功能并在Rails中运行5分钟后恢复

[英]How do I run pause my function and resume it after 5 min in rails

I have to send notification to nearest user and wait for 5 min for their response, in case of no response u have to send it to all users. 我必须向最近的用户发送通知,并等待5分钟以得到他们的响应,如果没有响应,则必须将其发送给所有用户。 I used thread.spleep(5.min) but it pause my whole program. 我使用thread.spleep(5.min),但它暂停了我的整个程序。 I read about background task but they will run after every 5 min but i have to run one part of fuction and then wait for 5 min while other work continues and then run remaining part again. 我阅读了有关后台任务的信息,但它们将每隔5分钟运行一次,但是我必须运行一部分功能,然后等待5分钟,同时其他工作继续进行,然后再次运行其余部分。

Whatever you want to execute after five minutes, put it in a background task. 五分钟后无论您要执行什么,都将其置于后台任务中。

If you use delayed_job, you can use run_at function. 如果使用run_at ,则可以使用run_at函数。 It will execute one time only (not every 5 mins). 它只会执行一次(不是每5分钟执行一次)。

Example: 例:

Notifier.delay(run_at: 5.minutes.from_now).signup(@user)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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