gpt4 book ai didi

ruby - 将 Ruby 脚本作为 Sinatra 的子进程/另一个线程运行的最佳方法是什么?

转载 作者:数据小太阳 更新时间:2023-10-29 07:17:16 25 4
gpt4 key购买 nike

我有一个 Sinatra 应用程序,我计划在 Heroku 上托管。

此应用程序从网络上的其他页面中部分地抓取大量信息并将信息存储到数据库中。这些报废操作是一个缓​​慢的过程,因此我需要它们在与我的 Sinatra 应用程序分开的另一个线程/进程中运行。

我的计划是为每个进程设置一个按钮,我可以单击该按钮,然后在后台进行报废。

我不确定执行此操作的最佳方法是什么,Heroku 允许的操作使它变得复杂。

最佳答案

有一个叫做 hirefire 的 gem专门为此:

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 - 将 Ruby 脚本作为 Sinatra 的子进程/另一个线程运行的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7393669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com