Resque: 如何为仅一个特定队列使用特定工作者

3
在我的Rails 5应用程序中,我使用Resque和Resque-scheduler向我的客户发送消息。为此,我为不同的消息创建了不同的队列,并创建了3个使用队列发送消息的worker。
因此,我的问题是,如何为一个特定的队列使用一个特定的worker?
例如,我有四个队列:birthday_checker,reminder_message,appointment_checker,confirmation_message。对于appointment_checker,我设置了cron,它将每56秒运行一次。为此,我的三个worker都忙于运行appointment_checker队列,而其他队列的工作正在等待中。但是我是否可以为这个appointment_checker队列保留一个worker?所以这可能吗?
我试图在Stack上找到一些相关的问题,但我找不到具体的解决方法。
这是我的resque.god文件代码。
rails_env   = ENV['RAILS_ENV']
rails_root  = File.dirname(__FILE__) + '/..'
num_workers = rails_env == 'production' ? 3 : 2

num_workers.times do |num|
 God.watch do |w|
   w.dir      = "#{rails_root}"
   w.name     = "resque-#{num}"
   w.group    = 'resque'
   w.interval = 30.seconds
   w.env      = {"QUEUE"=>"*", "RAILS_ENV"=>rails_env}
   w.start    = "bundle exec rake -f #{rails_root}/Rakefile environment resque:work"
   w.log      = "#{rails_root}/log/resque.log"
   w.err_log  = "#{rails_root}/log/resque_error.log"

#    w.uid = 'git'
#    w.gid = 'git'

   # restart if memory gets too high
   w.transition(:up, :restart) do |on|
     on.condition(:memory_usage) do |c|
       c.above = 350.megabytes
       c.times = 2
     end
   end

   # determine the state on startup
   w.transition(:init, { true => :up, false => :start }) do |on|
     on.condition(:process_running) do |c|
       c.running = true
     end
   end

   # determine when process has finished starting
   w.transition([:start, :restart], :up) do |on|
     on.condition(:process_running) do |c|
       c.running = true
       c.interval = 5.seconds
     end

     # failsafe
     on.condition(:tries) do |c|
       c.times = 5
       c.transition = :start
       c.interval = 5.seconds
     end
   end

   # start if process is not running
   w.transition(:up, :start) do |on|
     on.condition(:process_running) do |c|
       c.running = false
     end
   end
 end
end

这是lib/tasks/resque_scheduler.rake文件的代码

namespace :resque do
  task :setup => :environment do
    require 'resque'
    ENV['QUEUE'] = '*'
  end
  task :setup_schedule => :setup do
    require 'resque-scheduler'
    Resque.schedule = YAML.load_file('config/resque_schedule.yml')
  end
  task :scheduler => :setup_schedule
end

我尽力在stackoverflow上提出我的第一个问题,因此请忽略小错误,并为上述问题给我提供一些解决方案。 谢谢!

1个回答

1
"ENV['QUEUE'] = '*' 是匹配所有队列的通配符。每个队列将使用您排队的类的名称命名。只需用要运行的队列的名称替换 * 即可。"

谢谢Marlin,我知道这一点,但是我将*替换为我的队列名称,然后只运行特定的队列。那么我的其他队列该如何调用? - Risky leopard

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接