运行Ruby脚本作为Sinatra的子进程/另一个线程的最佳方式是什么? [英] What are the best ways to run a Ruby script as a subprocess/another thread from Sinatra?

查看:133
本文介绍了运行Ruby脚本作为Sinatra的子进程/另一个线程的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我准备在Heroku上托管一个Sinatra应用程序。

I have a Sinatra app I plan on hosting on Heroku.

这个应用程序部分地从其他的信息中删除了很多信息。网络周围的网页并将信息存储到数据库。这些报废操作是一个缓​​慢的过程,所以我需要他们运行另一个线程/过程独立于我的Sinatra应用程序。

This application, in part, scrapes a lot of information from other pages around the net and stores the information to a database. These scrapping operations are a slow process, so I need them to run in another thread/process separate from my Sinatra app.

我的计划只是为每个过程中,我可以点击,并在后台进行报废。

My plan is just to have a button for each process that I can click and the scrapping will take place in the background.

我不确定什么是最好的方式来做到这一点,由Heroku将允许。

I'm unsure what's the best way to do this, complicated by what Heroku will allow.

推荐答案

有一个叫做 hirefire 专门为此:

There's a gem called hirefire specifically for that:


HireFire会自动雇用和发火(又名鳞片)延迟作业
和Heroku上的Resque工人。当没有队列作业时,HireFire
将触发(关闭)所有工人。如果有排队的工作,那么
就会雇用(旋转)工人。雇佣
的工人数量取决于排队工作的数量(该比例可以由
来配置)。 HireFire适用于高,中,低流量的
应用。它只需在有待处理的工作时雇用工人
,然后在所有
工作处理完毕后再解雇他们,可以为您节省大量资金。它还能够通过在排队
大小增加时自动雇佣更多工人来显着减少
处理时间。

HireFire automatically "hires" and "fires" (aka "scales") Delayed Job and Resque workers on Heroku. When there are no queue jobs, HireFire will fire (shut down) all workers. If there are queued jobs, then it'll hire (spin up) workers. The amount of workers that get hired depends on the amount of queued jobs (the ratio can be configured by you). HireFire is great for both high, mid and low traffic applications. It can save you a lot of money by only hiring workers when there are pending jobs, and then firing them again once all the jobs have been processed. It's also capable to dramatically reducing processing time by automatically hiring more workers when the queue size increases.

这篇关于运行Ruby脚本作为Sinatra的子进程/另一个线程的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆