3

在我的 rails 5 应用程序中,我使用 resque 和 resque-scheduler 向我的客户发送消息。为此,我为消息创建了不同的不同队列,并创建了 3 个工作人员用于使用队列发送消息。所以,这里我的问题是我怎样才能为一个特定的队列使用一个特定的工作人员。 即我有四个队列,如生日检查器、提醒消息、约会检查器、确认消息。对于约会检查器,我设置了 cron 它将每 56 秒运行一次。为此,我的所有 3 名工作人员都忙于运行约会检查器队列。和其他正在等待的队列作业。但是我可以在这里为这个约会检查器队列保留一名工作人员。那么有可能吗?

我试着在堆栈上找到一些相关的问题,但我找不到具体的解决方案。

这是我的 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上提出我的第一个问题,所以请忽略小错误并为我提供上述问题的解决方案。谢谢!

4

1 回答 1

1

ENV['QUEUE'] = '*'是所有队列的通配符。每个队列都将具有您正在排队的类的名称。只需将 替换为*您要运行的队列的名称即可。

于 2019-05-17T08:28:02.543 回答