12

I am having trouble getting my dynos to run multiple delayed job worker processes.

My Procfile looks like this:

worker: bundle exec script/delayed_job -n 3 start

and my delayed_job script is the default provided by the gem:

#!/usr/bin/env ruby

require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
require 'delayed/command'
Delayed::Command.new(ARGV).daemonize

When I try to run this either locally or on a Heroku dyno it exits silently and I can't tell what is going on.

foreman start
16:09:09 worker.1 | started with pid 75417
16:09:15 worker.1 | exited with code 0
16:09:15 system   | sending SIGTERM to all processes
SIGTERM received

Any help with either how to debug the issue or suggestions about other ways to go about running multiple workers on a single dyno it would be greatly appreciated.

4

5 回答 5

15

您可以使用工头在同一个测功机上启动多个进程。

首先,将工头添加到您的 Gemfile。

然后worker在您的Procfile中添加一行:

worker: bundle exec foreman start -f Procfile.workers

创建一个名为Procfile.workers的新文件,其中包含:

dj_worker: bundle exec rake jobs:work
dj_worker: bundle exec rake jobs:work
dj_worker: bundle exec rake jobs:work

这将在您的工作人员测功机上启动 3 个延迟工作工作人员。

于 2014-07-25T04:40:33.337 回答
8

尝试将您的 Procfile 更改为:

worker: bundle exec script/delayed_job -n 3 run

Usingstart将在后台创建两个守护进程,然后立即退出。Heroku 认为您的进程崩溃了。

使用run使工作人员保持在前台。

更新:我现在为此使用延迟作业工人池。

于 2015-02-07T00:13:27.603 回答
0

简短的回答是你不能用delayed_job 做到这一点。测功机是一个进程,一个 delay_job 工作人员在一个进程上工作。

不过,还有其他解决方案。如果您可以切换到使用 Sidekiq,那么您可以在单个进程上运行相当多的工作人员,因为 Sidekiq 工作人员使用线程。这里的权衡是您的工作人员需要是线程安全的。

看看:http ://sidekiq.org/

于 2014-07-22T16:07:16.463 回答
0

我使用废墟 buildpack 在单个(工人)测功机中运行 Procfile.worker:https ://github.com/heroku/heroku-buildpack-runit

于 2022-02-01T03:22:11.380 回答
0

我尝试使用@infused 的公认解决方案,但遇到了工作进程在启动时崩溃的问题 Bundler::GemNotFound: Unable to find a spec satisfying web-console in the set. Perhaps the lockfile is corrupted?

原因是默认情况下foreman start正在寻找一个.env文件并阅读它:Forman Manual。因为该.env文件是为开发环境设置的,所以工头正在寻找web-consolegem 并错过了它。结论:如果您看到您的工作人员没有启动,请检查您是否有一个.env不适合生产的文件并将其重命名或在启动时指定另一个文件。

于 2020-07-13T09:44:27.430 回答