Skip to content

Commit

Permalink
Add validation checks for any job schedule exists
Browse files Browse the repository at this point in the history
  • Loading branch information
eisuke committed Jul 5, 2017
1 parent 7cb7676 commit 8d1ee24
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 3 additions & 1 deletion app/models/kuroko2/job_suspend_schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def suspend_times(time_from, time_to)
def validate_cron_schedule
if Kuroko2::JobSchedule::CRON_FORMAT === cron
suspend_schedule = Chrono::Schedule.new(cron)
unless job_definition.job_schedules.empty?
if job_definition.job_schedules.empty?
errors.add(:cron, "needs job schedules")
else
schedule = job_definition.job_schedules.each_with_object({}) do |launch_schedule_model, h|
launch_schedule = Chrono::Schedule.new(launch_schedule_model.cron)
Kuroko2::JobSchedule::CHRONO_SCHEDULE_METHODS.each do |method|
Expand Down
5 changes: 5 additions & 0 deletions spec/features/job_definition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
end
expect(page).to have_selector('#schedules table tbody tr .log', text: '* * * * *', count: 0)

fill_in 'job_suspend_schedule_cron', with: '* * * * *'
click_on 'Add Suspend Schedule'
expect(page).to have_content('Cron needs job schedules')
expect(page).to have_selector('#suspend-schedules table tbody tr .log', text: '* * * * *', count: 0)

fill_in 'job_schedule_cron', with: '* * * * *'
click_on 'Add Schedule'

Expand Down
9 changes: 5 additions & 4 deletions spec/models/job_schedule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

context 'With suspend_schelule' do
before do
create(:job_suspend_schedule, job_definition: definition, cron: '0-29 10 * * *')
create(:job_suspend_schedule, job_definition: schedule.job_definition, cron: '0-29 10 * * *')
end

it 'skips suspend time range' do
Expand All @@ -38,7 +38,8 @@

context 'When suspend schelules covers all schedule' do
before do
create(:job_suspend_schedule, job_definition: definition, cron: '0-50 10 * * *')
suspend_schedule = create(:job_suspend_schedule, job_definition: schedule.job_definition, cron: '50 10 * * *')
suspend_schedule.update_column(:cron, '0-50 10 * * *')
end

it 'returns nil' do
Expand All @@ -51,7 +52,7 @@
let(:cron) { '0 10 1-7 * *' }

before do
create(:job_suspend_schedule, job_definition: definition, cron: '* * * * 0-5')
create(:job_suspend_schedule, job_definition: schedule.job_definition, cron: '* * * * 0-5')
end

it 'returns next schedule' do
Expand All @@ -62,7 +63,7 @@
context 'When suspended schedule has wdays and days' do
let(:time) { Time.new(2016, 1, 2, 10, 0) }
before do
create(:job_suspend_schedule, job_definition: definition, cron: '* * 1 * 0') # suspend every sunday or first day of month
create(:job_suspend_schedule, job_definition: schedule.job_definition, cron: '* * 1 * 0') # suspend every sunday or first day of month
end

context 'If the schedule has days only' do
Expand Down

0 comments on commit 8d1ee24

Please sign in to comment.