开发者

With a Rails stack, how can I create a background process that handles events by spawning threads that are worked in real time?

With a Rails stack, how can I create a background process that handles events by spawning threads that are worked in real time开发者_C百科?

The workers on Heroku pick up jobs every 5 seconds. I need real time. Ideally I'd like to get this working on Heroku, but if I need to, I will move away from it.


This has a long list of background workers: Background Job Manager for Rails 3 but it is not clear if your question heroku specific or not


I think you are looking for something like "run_later" which instead of queueing a job actually returns the request and runs a block in a separate process.

Here is a link to the Rails 3+ version, you can follow the fork network to find many other implementations:

https://github.com/Zelnox/run_later

(I don't use Heroku so I don't know if it runs on it)


Heroku runs rake jobs:work, so you can replace that with your own rake task, either running delayed_job with a shorter than 5 second timeout, or just performing your own task. Probably a good idea to keep a sleep statement in there.

The new cedar stack will run anything you want, so it might be worth checking that out.

With regards to run_later, or spawning from the current request, this does work but if the background process doesn't complete within the 30 second request timeout then heroku will kill it.


I think you need delay_job. please checkout this gem

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜