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
Tatuya Kamada
gitlab-ce
Commits
914bef67
Commit
914bef67
authored
Apr 04, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move Ci::CronParser to Gitlab::Ci::CronParser
parent
27f981b2
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
55 additions
and
53 deletions
+55
-53
app/helpers/triggers_helper.rb
app/helpers/triggers_helper.rb
+2
-2
app/models/ci/trigger_schedule.rb
app/models/ci/trigger_schedule.rb
+1
-1
app/validators/cron_validator.rb
app/validators/cron_validator.rb
+1
-1
lib/ci/cron_parser.rb
lib/ci/cron_parser.rb
+0
-36
lib/gitlab/ci/cron_parser.rb
lib/gitlab/ci/cron_parser.rb
+38
-0
spec/factories/ci/trigger_schedules.rb
spec/factories/ci/trigger_schedules.rb
+4
-4
spec/helpers/triggers_helper_spec.rb
spec/helpers/triggers_helper_spec.rb
+7
-7
spec/models/ci/trigger_schedule_spec.rb
spec/models/ci/trigger_schedule_spec.rb
+1
-1
spec/workers/trigger_schedule_worker_spec.rb
spec/workers/trigger_schedule_worker_spec.rb
+1
-1
No files found.
app/helpers/triggers_helper.rb
View file @
914bef67
...
...
@@ -14,7 +14,7 @@ module TriggersHelper
def
real_next_run
(
trigger_schedule
,
worker_cron:
Settings
.
cron_jobs
[
'trigger_schedule_worker'
][
'cron'
],
worker_time_zone:
Time
.
zone
.
name
)
Ci
::
CronParser
.
new
(
worker_cron
,
worker_time_zone
)
Gitlab
::
Ci
::
CronParser
.
new
(
worker_cron
,
worker_time_zone
)
.
next_time_from
(
trigger_schedule
.
next_run_at
)
end
end
app/models/ci/trigger_schedule.rb
View file @
914bef67
...
...
@@ -18,7 +18,7 @@ module Ci
after_create
:schedule_next_run!
def
schedule_next_run!
next_time
=
Ci
::
CronParser
.
new
(
cron
,
cron_time_zone
).
next_time_from
(
Time
.
now
)
next_time
=
Gitlab
::
Ci
::
CronParser
.
new
(
cron
,
cron_time_zone
).
next_time_from
(
Time
.
now
)
update!
(
next_run_at:
next_time
)
if
next_time
.
present?
end
end
...
...
app/validators/cron_validator.rb
View file @
914bef67
...
...
@@ -3,7 +3,7 @@
# Custom validator for Cron.
class
CronValidator
<
ActiveModel
::
EachValidator
def
validate_each
(
record
,
attribute
,
value
)
cron_parser
=
Ci
::
CronParser
.
new
(
record
.
cron
,
record
.
cron_time_zone
)
cron_parser
=
Gitlab
::
Ci
::
CronParser
.
new
(
record
.
cron
,
record
.
cron_time_zone
)
is_valid_cron
,
is_valid_cron_time_zone
=
cron_parser
.
validation
if
!
is_valid_cron
...
...
lib/ci/cron_parser.rb
deleted
100644 → 0
View file @
27f981b2
module
Ci
class
CronParser
VALID_SYNTAX_SAMPLE_TIME_ZONE
=
'UTC'
.
freeze
VALID_SYNTAX_SAMPLE_CRON
=
'* * * * *'
.
freeze
def
initialize
(
cron
,
cron_time_zone
=
'UTC'
)
@cron
=
cron
@cron_time_zone
=
cron_time_zone
end
def
next_time_from
(
time
)
cron_line
=
try_parse_cron
(
@cron
,
@cron_time_zone
)
if
cron_line
.
present?
cron_line
.
next_time
(
time
).
in_time_zone
(
Time
.
zone
)
else
nil
end
end
def
validation
is_valid_cron
=
try_parse_cron
(
@cron
,
VALID_SYNTAX_SAMPLE_TIME_ZONE
).
present?
is_valid_cron_time_zone
=
try_parse_cron
(
VALID_SYNTAX_SAMPLE_CRON
,
@cron_time_zone
).
present?
return
is_valid_cron
,
is_valid_cron_time_zone
end
private
def
try_parse_cron
(
cron
,
cron_time_zone
)
begin
Rufus
::
Scheduler
.
parse
(
"
#{
cron
}
#{
cron_time_zone
}
"
)
rescue
nil
end
end
end
end
lib/gitlab/ci/cron_parser.rb
0 → 100644
View file @
914bef67
module
Gitlab
module
Ci
class
CronParser
VALID_SYNTAX_SAMPLE_TIME_ZONE
=
'UTC'
.
freeze
VALID_SYNTAX_SAMPLE_CRON
=
'* * * * *'
.
freeze
def
initialize
(
cron
,
cron_time_zone
=
'UTC'
)
@cron
=
cron
@cron_time_zone
=
cron_time_zone
end
def
next_time_from
(
time
)
cron_line
=
try_parse_cron
(
@cron
,
@cron_time_zone
)
if
cron_line
.
present?
cron_line
.
next_time
(
time
).
in_time_zone
(
Time
.
zone
)
else
nil
end
end
def
validation
is_valid_cron
=
try_parse_cron
(
@cron
,
VALID_SYNTAX_SAMPLE_TIME_ZONE
).
present?
is_valid_cron_time_zone
=
try_parse_cron
(
VALID_SYNTAX_SAMPLE_CRON
,
@cron_time_zone
).
present?
return
is_valid_cron
,
is_valid_cron_time_zone
end
private
def
try_parse_cron
(
cron
,
cron_time_zone
)
begin
Rufus
::
Scheduler
.
parse
(
"
#{
cron
}
#{
cron_time_zone
}
"
)
rescue
nil
end
end
end
end
end
\ No newline at end of file
spec/factories/ci/trigger_schedules.rb
View file @
914bef67
...
...
@@ -2,7 +2,7 @@ FactoryGirl.define do
factory
:ci_trigger_schedule
,
class:
Ci
::
TriggerSchedule
do
trigger
factory: :ci_trigger_for_trigger_schedule
cron
'0 1 * * *'
cron_time_zone
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_TIME_ZONE
cron_time_zone
Gitlab
::
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_TIME_ZONE
after
(
:build
)
do
|
trigger_schedule
,
evaluator
|
trigger_schedule
.
update!
(
project:
trigger_schedule
.
trigger
.
project
)
...
...
@@ -16,17 +16,17 @@ FactoryGirl.define do
trait
:cron_nightly_build
do
cron
'0 1 * * *'
cron_time_zone
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_TIME_ZONE
cron_time_zone
Gitlab
::
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_TIME_ZONE
end
trait
:cron_weekly_build
do
cron
'0 1 * * 6'
cron_time_zone
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_TIME_ZONE
cron_time_zone
Gitlab
::
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_TIME_ZONE
end
trait
:cron_monthly_build
do
cron
'0 1 22 * *'
cron_time_zone
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_TIME_ZONE
cron_time_zone
Gitlab
::
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_TIME_ZONE
end
end
end
spec/helpers/triggers_helper_spec.rb
View file @
914bef67
...
...
@@ -11,7 +11,7 @@ describe TriggersHelper do
let
(
:user_cron
)
{
'1 0 1 1 *'
}
# every 00:01, January 1st
it
'returns nearest worker_next_time from next_run_at'
do
is_expected
.
to
eq
(
Ci
::
CronParser
.
new
(
arguments
[
:worker_cron
],
arguments
[
:worker_time_zone
])
is_expected
.
to
eq
(
Gitlab
::
Ci
::
CronParser
.
new
(
arguments
[
:worker_cron
],
arguments
[
:worker_time_zone
])
.
next_time_from
(
trigger_schedule
.
next_run_at
))
end
end
...
...
@@ -21,7 +21,7 @@ describe TriggersHelper do
let
(
:user_cron
)
{
'0 0 1 1 *'
}
# every 00:00, January 1st
it
'returns nearest worker_next_time from next_run_at'
do
is_expected
.
to
eq
(
Ci
::
CronParser
.
new
(
arguments
[
:worker_cron
],
arguments
[
:worker_time_zone
])
is_expected
.
to
eq
(
Gitlab
::
Ci
::
CronParser
.
new
(
arguments
[
:worker_cron
],
arguments
[
:worker_time_zone
])
.
next_time_from
(
trigger_schedule
.
next_run_at
))
end
end
...
...
@@ -31,7 +31,7 @@ describe TriggersHelper do
let
(
:user_cron
)
{
'* * * * *'
}
# every minutes
it
'returns nearest worker_next_time from next_run_at by server configuration'
do
is_expected
.
to
eq
(
Ci
::
CronParser
.
new
(
Settings
.
cron_jobs
[
'trigger_schedule_worker'
][
'cron'
],
is_expected
.
to
eq
(
Gitlab
::
Ci
::
CronParser
.
new
(
Settings
.
cron_jobs
[
'trigger_schedule_worker'
][
'cron'
],
Time
.
zone
.
name
)
.
next_time_from
(
trigger_schedule
.
next_run_at
))
end
...
...
spec/models/ci/trigger_schedule_spec.rb
View file @
914bef67
...
...
@@ -13,7 +13,7 @@ describe Ci::TriggerSchedule, models: true do
end
it
'updates next_run_at'
do
next_time
=
Ci
::
CronParser
.
new
(
trigger_schedule
.
cron
,
trigger_schedule
.
cron_time_zone
).
next_time_from
(
Time
.
now
)
next_time
=
Gitlab
::
Ci
::
CronParser
.
new
(
trigger_schedule
.
cron
,
trigger_schedule
.
cron_time_zone
).
next_time_from
(
Time
.
now
)
expect
(
Ci
::
TriggerSchedule
.
last
.
next_run_at
).
to
eq
(
next_time
)
end
end
...
...
spec/workers/trigger_schedule_worker_spec.rb
View file @
914bef67
...
...
@@ -23,7 +23,7 @@ describe TriggerScheduleWorker do
end
it
'updates next_run_at'
do
next_time
=
Ci
::
CronParser
.
new
(
trigger_schedule
.
cron
,
trigger_schedule
.
cron_time_zone
).
next_time_from
(
Time
.
now
)
next_time
=
Gitlab
::
Ci
::
CronParser
.
new
(
trigger_schedule
.
cron
,
trigger_schedule
.
cron_time_zone
).
next_time_from
(
Time
.
now
)
expect
(
Ci
::
TriggerSchedule
.
last
.
next_run_at
).
to
eq
(
next_time
)
end
end
...
...
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