Skip to content

Commit

Permalink
Fix enqueue now exception
Browse files Browse the repository at this point in the history
  • Loading branch information
cdotta authored and snmgian committed Jul 29, 2016
1 parent 912dbd7 commit 57241d0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
7 changes: 6 additions & 1 deletion lib/sidekiq/scheduler.rb
Expand Up @@ -8,6 +8,7 @@ class Scheduler
extend Sidekiq::Util

REGISTERED_JOBS_THRESHOLD_IN_SECONDS = 24 * 60 * 60
RUFUS_METADATA_KEYS = %w(description at cron every in interval)

# We expect rufus jobs to have #params
Rufus::Scheduler::Job.module_eval do
Expand Down Expand Up @@ -239,7 +240,7 @@ def enque_with_active_job(config)
end

def enque_with_sidekiq(config)
Sidekiq::Client.push(config)
Sidekiq::Client.push(sanitize_job_config(config))
end

def initialize_active_job(klass, args)
Expand Down Expand Up @@ -351,6 +352,10 @@ def new_job(name, interval_type, config, args)
end
end

def sanitize_job_config(config)
config.reject { |k, _| RUFUS_METADATA_KEYS.include?(k) }
end

end
end
end
41 changes: 18 additions & 23 deletions spec/sidekiq/scheduler_spec.rb
Expand Up @@ -31,37 +31,23 @@
end

describe '.enqueue_job' do
it 'enqueue constantizes' do
# The job should be loaded, since a missing rails_env means ALL envs.
ENV['RAILS_ENV'] = 'production'

config = {
'cron' => '* * * * *',
let(:sidekiq_base_config) do
{
'class' => 'SomeWorker',
'queue' => 'high',
'args' => '/tmp'
}

expect(Sidekiq::Client).to receive(:push).with(process_parameters(config))

Sidekiq::Scheduler.enqueue_job(config)
end

it 'enqueue_job respects queue params' do
config = {
'cron' => '* * * * *',
'class' => 'SystemNotifierWorker',
'queue' => 'high'
}
it 'enqueue constantizes' do
# The job should be loaded, since a missing rails_env means ALL envs.
ENV['RAILS_ENV'] = 'production'

expect(Sidekiq::Client).to receive(:push).with({
'cron' => '* * * * *',
'class' => SystemNotifierWorker,
'args' => [],
'queue' => 'high'
})
scheduler_config = sidekiq_base_config.merge({ 'cron' => '* * * * *' })

expect(Sidekiq::Client).to receive(:push).with(process_parameters(sidekiq_base_config))

Sidekiq::Scheduler.enqueue_job(config)
Sidekiq::Scheduler.enqueue_job(scheduler_config)
end
end

Expand Down Expand Up @@ -610,6 +596,15 @@ def enqueued_jobs_registry
Sidekiq::Scheduler.enque_with_sidekiq(config)
}.to change { Sidekiq::Queues[config['queue']].size }.by(1)
end

context 'when the config have rufus related keys' do
let(:rufus_config) { { Sidekiq::Scheduler::RUFUS_METADATA_KEYS.sample => "value" } }

it 'removes those keys' do
expect(Sidekiq::Client).to receive(:push).with(config)
Sidekiq::Scheduler.enque_with_sidekiq(config.merge(rufus_config))
end
end
end

describe '.initialize_active_job' do
Expand Down

0 comments on commit 57241d0

Please sign in to comment.