Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix qless:work rake task #198

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions lib/qless/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,30 @@
namespace :qless do
task :setup # no-op; users should define their own setup

desc 'Start a worker with env: QUEUES, JOB_RESERVER, REDIS_URL, INTERVAL'
desc 'Start a worker with env: QUEUES, JOB_RESERVER, REDIS_URL, INTERVAL, WORKERS'
task work: :setup do
require 'qless/worker'
Qless::Worker.start
qless = Qless::Client.new
queues = ENV['QUEUES'].split(/\s*,\s*/).map { |name| qless.queues[name] }

job_reserver = case ENV['JOB_RESERVER']
when 'RoundRobin'
require 'qless/job_reservers/round_robin'
Qless::JobReservers::RoundRobin.new(queues)
when 'ShuffledRoundRobin'
require 'qless/job_reservers/shuffeled_round_robin'
Qless::JobReservers::ShuffeledRoundRobin.new(queues)
else
#Ordered job reserver is the default
require 'qless/job_reservers/ordered'
Qless::JobReservers::Ordered.new(queues)
end
log_level = Logger::DEBUG if ENV['VVERBOSE']
log_level ||= Logger::INFO if ENV['VERBOSE']
log_level ||= Logger::WARN
Qless::Workers::ForkingWorker.new(job_reserver,
:log_level => log_level,
:num_workers => (ENV['WORKERS'] || 1).to_i,
:interval => (ENV['INTERVAL'] || 2).to_i).run
end
end