簡體   English   中英

如何在 Rails 中每分鍾檢查一次時間

[英]How to check for time every minutes in Rails

假設我想構建一個提醒應用程序。 它允許用戶設置一個時間來提醒他們做他們的工作。 例如:3 月 24 日晚上 7:03。

我能想到的最簡單的方法是使用whenever並每分鍾設置一個 crontab 並檢查是否有任何提醒需要觸發。

但我想知道是否有更好的方法來實現這一點。 或者如果現在用戶想在幾秒鍾內設置提醒,我該怎么辦? 例如:3 月 24 日晚上 7:03:33。

另一種做到這一點並精確到秒的方法是延遲后台作業。

例如resque_scheduler

當用戶創建提醒時,您會在特定時間將作業排入隊列。

 reminder = Reminder.last
 # assuming reminder has a column reminder_at and there is 
 # a job that processes these reminders, ProcessReminderJob
 Resque.enqueue_at(reminder.remind_at, ProcessReminderJob, reminder.id)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM