简体   繁体   English

在Ruby on Rails中安排事件

[英]Scheduling events in Ruby on Rails

SO sorry if this is a duplicate, I tried searching for this but wasnt sure what search terms to use and didnt really find anything. 非常抱歉,如果这是重复的话,我尝试搜索此内容,但不确定要使用的搜索字词,还是没有真正找到任何内容。

I have a Ruby on Rails app that will be used to send text messages out to users that contain a link to a multiple choice question probably using clickatell. 我有一个Ruby on Rails应用程序,该应用程序将用于向用户发送文本消息,其中包含指向可能使用clickatell的多项选择问题的链接。 The questions have a date and time associated with them. 问题具有与之相关的日期和时间。 I want to make the ruby on rails app automatically send those SMS messages to the users' phones on those specified dates. 我想让ruby on rails应用程序在那些指定的日期自动将那些SMS消息发送到用户的手机。

I don't really know how one would go about doing this. 我真的不知道该怎么做。 Can anyone point me in the general direction of aa way to schedule events like this in ruby on rails. 谁能指出我的大致目标,以便在红宝石上安排此类事件。 I don't need an exact solution, maybe if someone could just clarify what exactly this is called so I can find some resources on line. 我不需要一个确切的解决方案,也许如果有人可以弄清楚这到底叫什么,以便我可以在线找到一些资源。

thanks 谢谢

It seems the sending out your questions is not reoccuring? 似乎您的问题没有再次发生? In this case I would not do this via a cronjob. 在这种情况下,我不会通过cronjob进行此操作。 I would do this via: https://github.com/bvandenbos/resque-scheduler 我可以通过以下方式做到这一点: https : //github.com/bvandenbos/resque-scheduler

So whenever a question is getting scheduled you just add it to the delayed queue and resque-scheduler handles moving them on the correct working queue when its time has come. 因此,只要计划了一个问题,您就可以将其添加到延迟的队列中,并且在时间到了时,resque-scheduler会将其移至正确的工作队列中。

This way you don't have to worry about some sort of polling cronjob, this will be done by resque-scheduler automatically. 这样,您不必担心某种轮询cronjob,这将由resque-scheduler自动完成。 You also get asynchronous handling of sending out the SMSes via resque for free. 您还可以通过异步方式免费获得通过resque发送SMS的异步处理。 So if you have to send lots and lots of SMS you can run them in parallel. 因此,如果您必须发送大量短信,则可以并行运行它们。

So it would go like this: 所以它会像这样:

  1. when a question is saved, you queue a message on the delayed queue in the future for sending out the question 保存问题后,您可以在以后的延迟队列中排队等待发送该问题的消息
  2. when the date comes up, the message is moved onto 'ready to send'-queue, which is in charge of gathering all the users the question needs to be sent to. 当日期到来时,消息将移至“准备发送”队列,该队列负责收集所有需要将问题发送给的用户。
  3. for each of those users you create another message on the 'ready to send'-queue 对于每个用户,您在“准备发送”队列上创建另一条消息
  4. the 'ready to send'-queue will then send out the actual SMSes 然后,“准备发送”队列将发出实际的SMS

You then can run many workers on the 'ready to send'-queue and have the SMSes be sent out in parallel. 然后,您可以在“准备发送”队列上运行许多工作程序,并使SMS并行发送。 You also get error handling for free with resque, it gahers all messages that resulted in an exception in a 'failure' queue, which you can then debug or reschedule again 您还可以通过resque免费获得错误处理,它可以处理导致“失败”队列中导致异常的所有消息,然后可以重新调试或重新计划

你可以使用每当调度事件。

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

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