3

in my rails 5 app i use resque and resque-scheduler for sending message to my customer.for that i created different different queue for messages and created 3 worker for sending message using queue. so, here my question is how can i use one specific worker for one specific queue. i.e i have four queue like birthday_checker, reminder_message, appointment_checker, confirmation_message. For appointment_checker i set cron it will run every 56s. for that my all 3 worker busy to run appointment_checker queue. and other queue job going in pending. but here can i reserve one worker for this appointment_checker queue. so is it possible?

i tried find some related questions on stack but i can't find specific solu for that.

Here is my resque.god file code

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

And this one is lib/tasks/resque_scheduler.rake file code

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

I tried my best to ask my first question on stackoverflow so please ignore small mistake and give me some solution for above question. Thanks!

Yury Matusevich
  • 988
  • 12
  • 22
Risky leopard
  • 91
  • 2
  • 8

1 Answers1

1

The ENV['QUEUE'] = '*' is a wildcard for all queues. Each Queue will have the name of the class you are queuing with. Just replace the * with the name of the queue you want to run.

Marlin Pierce
  • 9,931
  • 4
  • 30
  • 52
  • Thanks Marlin, i know that but here i replace the * to my queue name then only run that specific queue. then how my other queue will be call ? – Risky leopard May 17 '19 at 09:20