Skip to content

Commit

Permalink
Stringify queues when checking if a queue is listened on
Browse files Browse the repository at this point in the history
  • Loading branch information
snmgian committed May 15, 2017
1 parent 79d5a7e commit 25aaef1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/sidekiq/scheduler.rb
Expand Up @@ -63,9 +63,10 @@ def load_schedule!


@@scheduled_jobs = {}
queues = sidekiq_queues

Sidekiq.schedule.each do |name, config|
if !listened_queues_only || enabled_queue?(config['queue'])
if !listened_queues_only || enabled_queue?(config['queue'].to_s, queues)
load_schedule_job(name, config)
else
logger.info { "Ignoring #{name}, job's queue is not enabled." }
Expand Down Expand Up @@ -284,14 +285,15 @@ def try_to_constantize(klass)
klass
end

# Returns true if a job's queue is being listened on by sidekiq
# Returns true if a job's queue is included in the array of queues
#
# If queues are empty, returns true.
#
# @param [String] job_queue Job's queue name
# @param [Array<String>] queues
#
# @return [Boolean]
def enabled_queue?(job_queue)
queues = Sidekiq.options[:queues]

def enabled_queue?(job_queue, queues)
queues.empty? || queues.include?(job_queue)
end

Expand Down Expand Up @@ -413,6 +415,9 @@ def arguments_with_metadata(args, metadata)
end
end

def sidekiq_queues
Sidekiq.options[:queues].map(&:to_s)
end
end
end
end
26 changes: 26 additions & 0 deletions spec/sidekiq/scheduler_spec.rb
Expand Up @@ -268,6 +268,32 @@
end
end

context 'when stringified sidekiq queues match symbolized job\'s one' do
before do
Sidekiq.options[:queues] = ['reporting']
Sidekiq.schedule['some_ivar_job']['queue'] = :reporting
end

it 'loads the job into the scheduler' do
Sidekiq::Scheduler.load_schedule!

expect(Sidekiq::Scheduler.scheduled_jobs).to include('some_ivar_job')
end
end

context 'when symbolized sidekiq queues match stringified job\'s one' do
before do
Sidekiq.options[:queues] = ['reporting']
Sidekiq.schedule['some_ivar_job']['queue'] = :reporting
end

it 'loads the job into the scheduler' do
Sidekiq::Scheduler.load_schedule!

expect(Sidekiq::Scheduler.scheduled_jobs).to include('some_ivar_job')
end
end

context 'when sidekiq queues does not match job\'s one' do
before do
Sidekiq.options[:queues] = ['mailing']
Expand Down

0 comments on commit 25aaef1

Please sign in to comment.