Heroku上的rufus-scheduler和delayed_job:为什么要使用工人测功机? [英] rufus-scheduler and delayed_job on Heroku: why use a worker dyno?
问题描述
我正在开发一个Rails 3.2.16应用程序,并使用一个免费的Web dyno和没有工人dynos部署到Heroku dev帐户。我试图确定是否真的需要一个(付费的)工人测功机。
该应用程序发送各种电子邮件。我使用delayed_job_active_record将它们排队并发送出去。
我还需要每分钟检查一次通知计数。为此,我使用了rufus-scheduler。
rufus-scheduler似乎能够在Heroku web dyno中运行后台任务/线程。另一方面,我可以在delayed_job上找到的所有内容都表明它需要一个单独的工作进程。为什么?如果rufus-scheduler可以在web dyno中运行一个守护进程,为什么不能用delayed_job做同样的事情?
我测试了以下内容来运行我的每分钟任务和关闭delayed_jobs,它似乎可以在单个Heroku web dyno中工作:
$ b
config / initializers / rufus-scheduler。 rb
$ b
require'rufus-scheduler'
require'delayed /命令'
s = Rufus :: Scheduler.singleton
s.every'1m',:overlap =>假做#每分钟
Rails.logger.info>>#{Time.now}:rufus-scheduler任务开始
#检查未决通知并排队到delayed_job
用户.send_pending_notifications
#无需单独的工作进程即可关闭delayed_jobs
Delayed :: Worker.new.work_off
end
这似乎很明显,我想知道我是否错过了一些东西?这是一种可接受的方式来处理delayed_job队列,而不增加单独工作进程的复杂性和费用吗?
更新
正如@ jmettraux所指出的那样,Heroku会在一小时后闲置一个不活动的Web测试仪。我还没有设置它,但我们假设我正在使用其中一种保持活动的方法来防止它进入睡眠状态: 据此 https:// blog.heroku.com/archives/2013/6/20/app_sleeping_on_heroku 如果您的dyno没有提供一小时的服务请求, 。没有测功机,没有时间表。 这也有帮助: https://devcenter.heroku.com/articles/clock-processes-ruby I'm developing a Rails 3.2.16 app and deploying to a Heroku dev account with one free web dyno and no worker dynos. I'm trying to determine if a (paid) worker dyno is really needed. The app sends various emails. I use delayed_job_active_record to queue those and send them out. I also need to check a notification count every minute. For that I'm using rufus-scheduler. rufus-scheduler seems able to run a background task/thread within a Heroku web dyno. On the other hand, everything I can find on delayed_job indicates that it requires a separate worker process. Why? If rufus-scheduler can run a daemon within a web dyno, why can't delayed_job do the same? I've tested the following for running my every-minute task and working off delayed_jobs, and it seems to work within the single Heroku web dyno: config/initializers/rufus-scheduler.rb This seems so obvious that I'm wondering if I'm missing something? Is this an acceptable way to handle the delayed_job queue without the added complexity and expense of a separate worker process? Update As @jmettraux points out, Heroku will idle an inactive web dyno after an hour. I haven't set it up yet, but let's assume I'm using one of the various keep-alive methods to keep it from sleeping: Easy way to prevent Heroku idling?. According to this https://blog.heroku.com/archives/2013/6/20/app_sleeping_on_heroku your dyno will go to sleep if he hasn't serviced requests for an hour. No dyno, no scheduling. This could help as well: https://devcenter.heroku.com/articles/clock-processes-ruby 这篇关于Heroku上的rufus-scheduler和delayed_job:为什么要使用工人测功机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
require 'rufus-scheduler'
require 'delayed/command'
s = Rufus::Scheduler.singleton
s.every '1m', :overlap => false do # Every minute
Rails.logger.info ">> #{Time.now}: rufus-scheduler task started"
# Check for pending notifications and queue to delayed_job
User.send_pending_notifications
# work off delayed_jobs without a separate worker process
Delayed::Worker.new.work_off
end