AdrianoFerrari
AdrianoFerrari

Reputation: 2158

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. 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?

Upvotes: 1

Views: 221

Answers (1)

jonnii
jonnii

Reputation: 28312

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.

Upvotes: 1

Related Questions