简体   繁体   English

如何在Heroku上自动运行Queue_Classic(或任何)耙任务?

[英]How to run Queue_Classic (or any) rake task automatically on Heroku?

I have a Rails 3.2 app that uses the Queue_Classic gem, and is deployed on Heroku. 我有一个使用Queue_Classic gem的Rails 3.2应用程序,并将其部署在Heroku上。

Currently my queued jobs are not being processed, unless I run heroku run rake qc:work in the command line. 当前,除非我在命令行中运行heroku run rake qc:work ,否则不会处理我排队的作业。

I have added a Procfile containing the following: 我添加了包含以下内容的Procfile:

worker:  bundle exec rake qc:work

but still no processing of the queue unless I run heroku run rake qc:work manually. 但是除非我手动运行heroku run rake qc:work否则仍然不会处理队列。

What am I missing? 我想念什么?

This app uses Unicorn, could this be having an impact? 该应用程序使用独角兽,这会产生影响吗?

Typically your workers run independently from your web processes. 通常,您的工作人员独立于Web流程运行。 To run a worker, you need to set your process formation to run 1 worker: 要运行一个工作程序,您需要将您的流程形式设置为运行一个工作程序:

$ heroku scale worker=1

*请确保在主Rakefile中包括queue_classic和queue_classic / tasks。*

After some digging around, I came up with the following solution. 经过深入研究后,我提出了以下解决方案。

I'm not sure if this is the best approach, or how it will behave as we scale web processes etc, but it's working for now. 我不确定这是否是最好的方法,或者在扩展Web流程等过程中它的表现如何,但目前仍在工作。

I set up unicorn as usual, including 我像往常一样设置了独角兽,包括

#Procfile
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb 

then i added the following config 然后我添加了以下配置

#unicorn.rb
worker_processes 3 
timeout 30

@qc_pid = nil

before_fork do |server, worker|
  @qc_pid ||= spawn( "bundle exec rake qc:work" )
end

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

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