diff --git a/lib/delayed/command.rb b/lib/delayed/command.rb index a3691d68d..cedd5338b 100644 --- a/lib/delayed/command.rb +++ b/lib/delayed/command.rb @@ -70,6 +70,14 @@ def initialize(args) # rubocop:disable MethodLength opt.on('--queue=queue', 'Specify which queue DJ must look up for jobs') do |queue| @options[:queues] = queue.split(',') end + opt.on('--exclude_queues=queues', 'Specify which queues DJ must NOT look up for jobs') do |exclude_queues| + @options[:exlude_queues] = exclude_queues.split(',') + end + opt.on('--eval_queues=evalstring', "Specify a string, which will be eval'ed to where() while lookup. E.g. \"['created_at < ',2.days.ago]\"") do |eval_queues| + # this will fail (throwing an exception), if option eval_queues is not a valid argument to eval or where + Delayed::Job.where(eval(eval_queues)).any? + @options[:eval_queues] = eval_queues + end opt.on('--pool=queue1[,queue2][:worker_count]', 'Specify queues and number of workers for a worker pool') do |pool| parse_worker_pool(pool) end diff --git a/lib/delayed/worker.rb b/lib/delayed/worker.rb index 3f5fac473..eb7a2ed5a 100644 --- a/lib/delayed/worker.rb +++ b/lib/delayed/worker.rb @@ -15,6 +15,8 @@ class Worker # rubocop:disable ClassLength DEFAULT_DEFAULT_PRIORITY = 0 DEFAULT_DELAY_JOBS = true DEFAULT_QUEUES = [] + DEFAULT_EXCLUDE_QUEUES = [] + DEFAULT_EVAL_QUEUES = nil DEFAULT_READ_AHEAD = 5 cattr_accessor :min_priority, :max_priority, :max_attempts, :max_run_time, @@ -25,6 +27,10 @@ class Worker # rubocop:disable ClassLength # Named queue into which jobs are enqueued by default cattr_accessor :default_queue_name + # Named queues to exclude + cattr_accessor :exclude_queues, :eval_queues + + cattr_reader :backend # name_prefix is ignored if name is set directly @@ -38,6 +44,8 @@ def self.reset self.default_priority = DEFAULT_DEFAULT_PRIORITY self.delay_jobs = DEFAULT_DELAY_JOBS self.queues = DEFAULT_QUEUES + self.exclude_queues = DEFAULT_EXCLUDE_QUEUES + self.eval_queues = DEFAULT_EVAL_QUEUES self.read_ahead = DEFAULT_READ_AHEAD @lifecycle = nil end @@ -125,7 +133,7 @@ def initialize(options = {}) @quiet = options.key?(:quiet) ? options[:quiet] : true @failed_reserve_count = 0 - [:min_priority, :max_priority, :sleep_delay, :read_ahead, :queues, :exit_on_complete].each do |option| + [:min_priority, :max_priority, :sleep_delay, :read_ahead, :queues, :exit_on_complete, :exclude_queues, :eval_queues].each do |option| self.class.send("#{option}=", options[option]) if options.key?(option) end