Commit 673ea5d2 authored by Fabio Pitino's avatar Fabio Pitino

Rescue RuntimeError when "too many loops" occur

With this workaround we temporarily prevent an
exception from Fugit gem to be raised in
Gitlab::Ci::CronParser
parent 0edd1e67
......@@ -13,7 +13,7 @@ module Gitlab
def next_time_from(time)
@cron_line ||= try_parse_cron(@cron, @cron_timezone)
@cron_line.next_time(time).utc.in_time_zone(Time.zone) if @cron_line.present?
find_next_time(time) if @cron_line.present?
end
def cron_valid?
......@@ -49,6 +49,14 @@ module Gitlab
def try_parse_cron(cron, cron_timezone)
Fugit::Cron.parse("#{cron} #{cron_timezone}")
end
def find_next_time(time)
@cron_line.next_time(time).utc.in_time_zone(Time.zone)
rescue RuntimeError => error
raise error unless error.message =~ /too many loops/
# Fugit::Cron raises a RuntimeError if :next_time does not find the next schedule
# given an invalid pattern - E.g. try_parse_cron('0 12 31 2 *')
end
end
end
end
......@@ -181,6 +181,13 @@ describe Gitlab::Ci::CronParser do
it { expect(subject).to be_nil }
end
context 'when cron is scheduled to a non existent day' do
let(:cron) { '0 12 31 2 *' }
let(:cron_timezone) { 'UTC' }
it { expect(subject).to be_nil }
end
end
describe '#cron_valid?' do
......
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