Sidekiq - 防止工作人员在特定机器上执行
Sidekiq - Prevent worker from being executed in specific machine
我正在开发一个使用 Sidekiq 的 Rails 项目。我们的 Sidekiq 实现有两个 worker(WorkerA,读取 queue_a,和 WorkerB,读取 queue_b)。其中一个必须在 Rails 应用程序所在的同一服务器中执行,另一个必须在不同的服务器中执行。如何防止 WorkerB 在第一台服务器上执行,反之亦然?能否将 Sidekiq 进程配置为 运行 特定工作人员?
编辑:
Redis 服务器与 Rails 应用程序在同一台机器上。
好吧,这是使用选项启动 sidekiq 的方法
nohup bundle exec sidekiq -q queue_a queue_b -c 5 -e #{Rails.env} -P #{pidfile} 2>&1 &
您可以使用特定的工作人员启动 sidekiq
您可以运行 nohup bundle exec sidekiq -q queue_a -c 5 -e #{Rails.env} -P #{pidfile} 2>&1 &
只执行 WorkA
区分不同服务器上的不同worker,如下所示:
system "nohup bundle exec sidekiq -q #{workers_string} -c 5 -e #{Rails.env} -P #{pidfile} 2>&1 &"
def workers_string
if <on server A> # using ENV or serverip to distinguish
"queue_a"
elsif <on server B>
"queue_b queue_b ..."
end
end
#or you can set the workers_strings into config file on different servers
使用特定于主机名的队列。 config/sidekiq.yml:
---
:verbose: false
:concurrency: 25
:queues:
- default
- <%= `hostname`.strip %>
在你的工人中:
class ImageUploadProcessor
include Sidekiq::Worker
sidekiq_options queue: `hostname`.strip
def perform(filename)
# process image
end
end
我的博客上有更多详细信息:
http://www.mikeperham.com/2013/11/13/advanced-sidekiq-host-specific-queues/
我正在开发一个使用 Sidekiq 的 Rails 项目。我们的 Sidekiq 实现有两个 worker(WorkerA,读取 queue_a,和 WorkerB,读取 queue_b)。其中一个必须在 Rails 应用程序所在的同一服务器中执行,另一个必须在不同的服务器中执行。如何防止 WorkerB 在第一台服务器上执行,反之亦然?能否将 Sidekiq 进程配置为 运行 特定工作人员?
编辑: Redis 服务器与 Rails 应用程序在同一台机器上。
好吧,这是使用选项启动 sidekiq 的方法
nohup bundle exec sidekiq -q queue_a queue_b -c 5 -e #{Rails.env} -P #{pidfile} 2>&1 &
您可以使用特定的工作人员启动 sidekiq
您可以运行 nohup bundle exec sidekiq -q queue_a -c 5 -e #{Rails.env} -P #{pidfile} 2>&1 &
只执行 WorkA
区分不同服务器上的不同worker,如下所示:
system "nohup bundle exec sidekiq -q #{workers_string} -c 5 -e #{Rails.env} -P #{pidfile} 2>&1 &"
def workers_string
if <on server A> # using ENV or serverip to distinguish
"queue_a"
elsif <on server B>
"queue_b queue_b ..."
end
end
#or you can set the workers_strings into config file on different servers
使用特定于主机名的队列。 config/sidekiq.yml:
---
:verbose: false
:concurrency: 25
:queues:
- default
- <%= `hostname`.strip %>
在你的工人中:
class ImageUploadProcessor
include Sidekiq::Worker
sidekiq_options queue: `hostname`.strip
def perform(filename)
# process image
end
end
我的博客上有更多详细信息:
http://www.mikeperham.com/2013/11/13/advanced-sidekiq-host-specific-queues/