你如何在一个Heroku dyno上运行多个DelayedJob工作者?

时间:2022-08-20 19:17:27

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

我无法让我的dynos运行多个延迟的工作进程。

My Procfile looks like this:

我的Procfile看起来像这样:

worker: bundle exec script/delayed_job -n 3 start

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

我的delayed_job脚本是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.

当我尝试在本地或在Heroku dyno上运行它时,它会静静地退出,我无法分辨出发生了什么。

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.

任何有关如何调试问题的帮助或关于在单个dyno上运行多个工作人员的其他方法的建议将非常感激。

3 个解决方案

#1


13  

You can use foreman to start multiple processes on the same dyno.

您可以使用foreman在同一个dyno上启动多个进程。

First, add foreman to your Gemfile.

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

Then add a worker line to your Procfile:

然后在Procfile中添加一个工作线:

worker: bundle exec foreman start -f Procfile.workers

Create a new file called Procfile.workers which contains:

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

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

That will start 3 delayed_job workers on your worker dyno.

这将在你的工人dyno上启动3个delayed_job工人。

#2


6  

Try changing your Procfile to:

尝试将Procfile更改为:

worker: bundle exec script/delayed_job -n 3 run

worker:bundle exec script / delayed_job -n 3 run

Using start will create two daemons in the background and then immediately exit. Heroku thinks that your process crashed.

使用start将在后台创建两个守护进程,然后立即退出。 Heroku认为你的过程崩溃了。

Using run keeps the workers in the foreground.

使用run可将工作人员置于前台。

UPDATE: I use Delayed Job Worker Pool for this now.

更新:我现在使用延迟工作池。

#3


0  

Short answer is that you can't do this with delayed_job. A dyno is a process and a single delayed_job worker works on a single process.

简短的回答是你不能用delayed_job做到这一点。 dyno是一个进程,单个delayed_job工作程序在单个进程上工作。

There are other solutions to this though. If you can switch over to using Sidekiq then you can run quite a few workers on a single process since Sidekiq workers use threading. The trade-off here is that your workers will need to be thread safe.

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

Check it out: http://sidekiq.org/

看看:http://sidekiq.org/

#1


13  

You can use foreman to start multiple processes on the same dyno.

您可以使用foreman在同一个dyno上启动多个进程。

First, add foreman to your Gemfile.

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

Then add a worker line to your Procfile:

然后在Procfile中添加一个工作线:

worker: bundle exec foreman start -f Procfile.workers

Create a new file called Procfile.workers which contains:

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

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

That will start 3 delayed_job workers on your worker dyno.

这将在你的工人dyno上启动3个delayed_job工人。

#2


6  

Try changing your Procfile to:

尝试将Procfile更改为:

worker: bundle exec script/delayed_job -n 3 run

worker:bundle exec script / delayed_job -n 3 run

Using start will create two daemons in the background and then immediately exit. Heroku thinks that your process crashed.

使用start将在后台创建两个守护进程,然后立即退出。 Heroku认为你的过程崩溃了。

Using run keeps the workers in the foreground.

使用run可将工作人员置于前台。

UPDATE: I use Delayed Job Worker Pool for this now.

更新:我现在使用延迟工作池。

#3


0  

Short answer is that you can't do this with delayed_job. A dyno is a process and a single delayed_job worker works on a single process.

简短的回答是你不能用delayed_job做到这一点。 dyno是一个进程,单个delayed_job工作程序在单个进程上工作。

There are other solutions to this though. If you can switch over to using Sidekiq then you can run quite a few workers on a single process since Sidekiq workers use threading. The trade-off here is that your workers will need to be thread safe.

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

Check it out: http://sidekiq.org/

看看:http://sidekiq.org/