Skip to content

Commit

Permalink
raise error on invalid cron config
Browse files Browse the repository at this point in the history
  • Loading branch information
alachaum committed Apr 11, 2024
1 parent 047e2d9 commit 612d212
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/cloudtasker/cron/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def flag(state)
# not lead to a new task getting scheduled).
#
def schedule!
return false unless cron_schedule && next_time
return false unless cron_schedule

# Configure next cron worker
next_worker = worker.new_instance.tap { |e| e.job_meta.set(key(:time_at), next_time.iso8601) }
Expand Down
4 changes: 2 additions & 2 deletions lib/cloudtasker/cron/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def to_h
# @return [Fugit::Cron] The cron schedule.
#
def cron_schedule
@cron_schedule ||= Fugit::Cron.parse(cron)
@cron_schedule ||= Fugit::Cron.do_parse(cron)
end

#
Expand All @@ -245,7 +245,7 @@ def worker_instance
# @return [EtOrbi::EoTime] The time the schedule job should run next.
#
def next_time(*args)
cron_schedule&.next_time(*args)
cron_schedule.next_time(*args)
end

#
Expand Down
7 changes: 0 additions & 7 deletions spec/cloudtasker/cron/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,6 @@
it { is_expected.to be_falsey }
end

context 'with no next_time' do
before { allow(job).to receive(:next_time).and_return(nil) }

before { expect(next_worker).not_to receive(:schedule) }
it { is_expected.to be_falsey }
end

context 'with cron_schedule' do
before { expect(next_worker).to receive(:schedule).with(time_at: job.next_time).and_return(resp) }
after { expect(next_worker.job_meta.get(job.key(:time_at))).to eq(job.next_time.iso8601) }
Expand Down
21 changes: 11 additions & 10 deletions spec/cloudtasker/cron/schedule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,24 +299,25 @@
end

describe '#cron_schedule' do
subject { schedule.cron_schedule }
subject(:cron_schedule) { schedule.cron_schedule }

it { is_expected.to eq(Fugit::Cron.parse(cron)) }
context 'with valid cron definition' do
it { is_expected.to eq(Fugit::Cron.parse(cron)) }
end

context 'with invalid cron definition' do
let(:cron) { 'random string' }

it { expect { cron_schedule }.to raise_error(ArgumentError) }
end
end

describe '#next_time' do
subject { schedule.next_time(now) }

let(:now) { Time.now }

context 'with cron_schedule' do
it { is_expected.to eq(schedule.cron_schedule.next_time(now)) }
end

context 'with nil cron_schedule' do
before { allow(schedule).to receive(:cron_schedule).and_return(nil) }
it { is_expected.to be_nil }
end
it { is_expected.to eq(schedule.cron_schedule.next_time(now)) }
end

describe '#assign_attributes' do
Expand Down

0 comments on commit 612d212

Please sign in to comment.