Commit 97cc6777 authored by Shinya Maeda's avatar Shinya Maeda

Commentout check_cron_frequency

parent 1bd54949
......@@ -13,30 +13,32 @@ module Ci
validates :cron, cron: true, presence: true
validates :cron_time_zone, presence: true
validates :ref, ref: true, presence: true
validate :check_cron_frequency
# validate :check_cron_frequency
after_create :schedule_next_run!
def schedule_next_run!
next_time = Ci::CronParser.new(cron, cron_time_zone).next_time_from(Time.now)
if next_time.present? && !less_than_1_hour_from_now?(next_time)
# if next_time.present? && !less_than_1_hour_from_now?(next_time)
if next_time.present?
update!(next_run_at: next_time)
end
end
private
# private
def less_than_1_hour_from_now?(time)
((time - Time.now).abs < 1.hour) ? true : false
end
# def less_than_1_hour_from_now?(time)
# puts "diff: #{(time - Time.now).abs.inspect}"
# ((time - Time.now).abs < 1.hour) ? true : false
# end
def check_cron_frequency
next_time = Ci::CronParser.new(cron, cron_time_zone).next_time_from(Time.now)
# def check_cron_frequency
# next_time = Ci::CronParser.new(cron, cron_time_zone).next_time_from(Time.now)
if less_than_1_hour_from_now?(next_time)
self.errors.add(:cron, " can not be less than 1 hour")
end
end
# if less_than_1_hour_from_now?(next_time)
# self.errors.add(:cron, " can not be less than 1 hour")
# end
# end
end
end
......@@ -12,33 +12,8 @@ describe Ci::TriggerSchedule, models: true do
expect(trigger_schedule.errors[:ref].first).to include('does not exist')
end
describe 'cron limitation' do
let(:trigger_schedule) { create(:ci_trigger_schedule, :cron_nightly_build) }
before do
trigger_schedule.cron = cron
trigger_schedule.valid?
end
context 'when cron frequency is too short' do
let(:cron) { '0 * * * *' } # 00:00, 01:00, 02:00, ..., 23:00
it 'gets an error' do
expect(trigger_schedule.errors[:cron].first).to include('can not be less than 1 hour')
end
end
context 'when cron frequency is eligible' do
let(:cron) { '0 0 1 1 *' } # every 00:00, January 1st
it 'gets no errors' do
expect(trigger_schedule.errors[:cron]).to be_empty
end
end
end
describe '#schedule_next_run!' do
let(:trigger_schedule) { create(:ci_trigger_schedule, :cron_nightly_build) }
let(:trigger_schedule) { create(:ci_trigger_schedule, :cron_nightly_build, next_run_at: nil) }
before do
trigger_schedule.schedule_next_run!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment