Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
97cc6777
Commit
97cc6777
authored
Apr 01, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Commentout check_cron_frequency
parent
1bd54949
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
38 deletions
+15
-38
app/models/ci/trigger_schedule.rb
app/models/ci/trigger_schedule.rb
+14
-12
spec/models/ci/trigger_schedule_spec.rb
spec/models/ci/trigger_schedule_spec.rb
+1
-26
No files found.
app/models/ci/trigger_schedule.rb
View file @
97cc6777
...
...
@@ -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
spec/models/ci/trigger_schedule_spec.rb
View file @
97cc6777
...
...
@@ -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!
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment