Skip to content

Commit

Permalink
Do not attempt to set job next_time when job is nil (#445)
Browse files Browse the repository at this point in the history
Having an `at`-rule in sidekiq.yml with a date in the past results in a undefined method `next_time' for nil:NilClass.
  • Loading branch information
mauricebolhuis authored and marcelolx committed May 16, 2024
1 parent 1e8d186 commit 5b71586
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lib/sidekiq-scheduler/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def load_schedule_job(name, config)
schedule, options = SidekiqScheduler::RufusUtils.normalize_schedule_options(config_interval_type)

rufus_job = new_job(name, interval_type, config, schedule, options)
return unless rufus_job

@scheduled_jobs[name] = rufus_job
SidekiqScheduler::Utils.update_job_next_time(name, rufus_job.next_time)

Expand Down
36 changes: 28 additions & 8 deletions spec/sidekiq-scheduler/scheduler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -698,18 +698,38 @@
end

context 'at schedule' do
let(:config) { ScheduleFaker.at_schedule(at: Time.now + 60) }
let(:config) { ScheduleFaker.at_schedule(at: at) }

it 'adds the job to rufus scheduler' do
expect(instance.rufus_scheduler.jobs.size).to eq(1)
end
context 'in the future' do
let(:at) { Time.now + 60 }

it 'puts the job inside the scheduled hash' do
expect(instance.scheduled_jobs.keys).to eq([job_name])
it 'adds the job to rufus scheduler' do
expect(instance.rufus_scheduler.jobs.size).to eq(1)
end

it 'puts the job inside the scheduled hash' do
expect(instance.scheduled_jobs.keys).to eq([job_name])
end

it 'stores the next time execution correctly' do
expect(next_time_execution).to be
end
end

it 'stores the next time execution correctly' do
expect(next_time_execution).to be
context 'in the past' do
let(:at) { Time.now - 60 }

it 'does not add the job to rufus scheduler' do
expect(instance.rufus_scheduler.jobs).to be_empty
end

it 'does not put the job inside the scheduled hash' do
expect(instance.scheduled_jobs.keys).not_to include(job_name)
end

it 'stores the next time execution correctly' do
expect(next_time_execution).not_to be
end
end
end

Expand Down

0 comments on commit 5b71586

Please sign in to comment.