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

Commentout check_cron_frequency

parent 1bd54949
...@@ -13,30 +13,32 @@ module Ci ...@@ -13,30 +13,32 @@ module Ci
validates :cron, cron: true, presence: true validates :cron, cron: true, presence: true
validates :cron_time_zone, presence: true validates :cron_time_zone, presence: true
validates :ref, ref: true, presence: true validates :ref, ref: true, presence: true
validate :check_cron_frequency # validate :check_cron_frequency
after_create :schedule_next_run! after_create :schedule_next_run!
def schedule_next_run! def schedule_next_run!
next_time = Ci::CronParser.new(cron, cron_time_zone).next_time_from(Time.now) 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) update!(next_run_at: next_time)
end end
end end
private # private
def less_than_1_hour_from_now?(time) # def less_than_1_hour_from_now?(time)
((time - Time.now).abs < 1.hour) ? true : false # puts "diff: #{(time - Time.now).abs.inspect}"
end # ((time - Time.now).abs < 1.hour) ? true : false
# end
def check_cron_frequency # def check_cron_frequency
next_time = Ci::CronParser.new(cron, cron_time_zone).next_time_from(Time.now) # next_time = Ci::CronParser.new(cron, cron_time_zone).next_time_from(Time.now)
if less_than_1_hour_from_now?(next_time) # if less_than_1_hour_from_now?(next_time)
self.errors.add(:cron, " can not be less than 1 hour") # self.errors.add(:cron, " can not be less than 1 hour")
end # end
end # end
end end
end end
...@@ -12,33 +12,8 @@ describe Ci::TriggerSchedule, models: true do ...@@ -12,33 +12,8 @@ describe Ci::TriggerSchedule, models: true do
expect(trigger_schedule.errors[:ref].first).to include('does not exist') expect(trigger_schedule.errors[:ref].first).to include('does not exist')
end 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 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 before do
trigger_schedule.schedule_next_run! 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