简体   繁体   English

Rails:如何每n分钟发送(更改)http POST?

[英]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. 我需要将消息http发布到特定的SMS网关。 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). 每个参数都代表我建立http发布请求所需的参数,并且需要在send_time (给定或花费几分钟)上发送。

I currently have a rake task every minute, that checks the db and sends the POSTs accordingly. 我目前每分钟都有一次rake任务,该任务检查数据库并相应地发送POST。 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? 将如何解决这个问题?

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. 延迟的工作resque支持都稍后发送(这不是resque中的头等舱,但有示例),因此这两者都是完成此任务的不错选择。

To make this scale you would add more workers to consume the messages. 为了达到这种规模,您将添加更多的工作人员来使用消息。

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

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