开发者

Rails: How to send (changing) http POST every n minutes?

Please help me out.

I need to http post messages to a particular SMS gateway. So, I have a table similar to this:

|     send_time     |  phone    |          msg          |
|2010-03-15 08:30:00|12125551234|'first message user A' |
|2010-03-15 09:30:00|12125551234|'secnd message user A' |
|2010-03-15 08:30:00|15145550000|'first message user B' |

Each one represents the parameters I need to build the http post request, and it needs to be sent at the send_time (give or take a few minutes).

I currently have a rake task every minute, that checks the db and sends the POSTs accordingly. But that seems a flimsy way to go about it. 开发者_Python百科Besides, this needs to scale very well; I will have to be able send many (let's say thousands) in a given minute.

How would you tackle this problem?


This is the kind of job that is best done by a background worker. Every text message that needs to be sent would be a job with a given time to run.

Both delayed job and resque support send later (it's not first class yet in resque, but there are examples), so both of those would be good choices for this task.

To make this scale you would add more workers to consume the messages.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜