Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Metrics/MethodLength:
# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 368
Max: 373

# Offense count: 1
Style/CaseEquality:
Expand Down
9 changes: 7 additions & 2 deletions lib/resque/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,13 @@ def load_schedule_job(name, config)
args = optionizate_interval_value(config[interval_type])
args = [args, nil, job: true] if args.is_a?(::String)

job = rufus_scheduler.send(interval_type, *args) do
enqueue_recurring(name, config)
begin
job = rufus_scheduler.send(interval_type, *args) do
enqueue_recurring(name, config)
end
rescue ArgumentError => e
log_error "Invalid #{interval_type} schedule for #{name}: #{e.message} - skipping"
return
end
@scheduled_jobs[name] = job
interval_defined = true
Expand Down
30 changes: 30 additions & 0 deletions test/scheduler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,36 @@
assert Resque::Scheduler.scheduled_jobs.keys.include?('some_ivar_job')
end

test 'load_schedule_job skips an invalid cron with options' do
Resque::Scheduler.expects(:log_error).with(
regexp_matches(/Invalid cron schedule for bad_job:/)
)

Resque::Scheduler.load_schedule_job(
'bad_job',
'cron' => ['not a cron', { 'allow_overlapping' => 'true' }],
'class' => 'SomeIvarJob'
)

assert_empty Resque::Scheduler.rufus_scheduler.jobs
assert_empty Resque::Scheduler.scheduled_jobs
end

test 'load_schedule continues after an invalid cron' do
Resque.schedule = {
'bad_job' => { 'cron' => 'not a cron', 'class' => 'SomeIvarJob' },
'good_job' => { 'cron' => '* * * * *', 'class' => 'SomeIvarJob' }
}
Resque::Scheduler.expects(:log_error).with(
regexp_matches(/Invalid cron schedule for bad_job:/)
)

Resque::Scheduler.load_schedule!

assert_equal ['good_job'], Resque::Scheduler.scheduled_jobs.keys
assert_equal 1, Resque::Scheduler.rufus_scheduler.jobs.size
end

test 'load_schedule_job with every with options' do
Resque::Scheduler.load_schedule_job(
'some_ivar_job',
Expand Down
Loading