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
1
Merge Requests
1
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
nexedi
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
...
@@ -14,7 +14,7 @@ module TriggersHelper
def
real_next_run
(
trigger_schedule
,
def
real_next_run
(
trigger_schedule
,
worker_cron:
Settings
.
cron_jobs
[
'trigger_schedule_worker'
][
'cron'
],
worker_cron:
Settings
.
cron_jobs
[
'trigger_schedule_worker'
][
'cron'
],
worker_time_zone:
Time
.
zone
.
name
)
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
)
.
next_time_from
(
trigger_schedule
.
next_run_at
)
end
end
end
end
app/models/ci/trigger_schedule.rb
View file @
914bef67
...
@@ -18,7 +18,7 @@ module Ci
...
@@ -18,7 +18,7 @@ module Ci
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
=
Gitlab
::
Ci
::
CronParser
.
new
(
cron
,
cron_time_zone
).
next_time_from
(
Time
.
now
)
update!
(
next_run_at:
next_time
)
if
next_time
.
present?
update!
(
next_run_at:
next_time
)
if
next_time
.
present?
end
end
end
end
...
...
app/validators/cron_validator.rb
View file @
914bef67
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
# Custom validator for Cron.
# Custom validator for Cron.
class
CronValidator
<
ActiveModel
::
EachValidator
class
CronValidator
<
ActiveModel
::
EachValidator
def
validate_each
(
record
,
attribute
,
value
)
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
is_valid_cron
,
is_valid_cron_time_zone
=
cron_parser
.
validation
if
!
is_valid_cron
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
...
@@ -2,7 +2,7 @@ FactoryGirl.define do
factory
:ci_trigger_schedule
,
class:
Ci
::
TriggerSchedule
do
factory
:ci_trigger_schedule
,
class:
Ci
::
TriggerSchedule
do
trigger
factory: :ci_trigger_for_trigger_schedule
trigger
factory: :ci_trigger_for_trigger_schedule
cron
'0 1 * * *'
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
|
after
(
:build
)
do
|
trigger_schedule
,
evaluator
|
trigger_schedule
.
update!
(
project:
trigger_schedule
.
trigger
.
project
)
trigger_schedule
.
update!
(
project:
trigger_schedule
.
trigger
.
project
)
...
@@ -16,17 +16,17 @@ FactoryGirl.define do
...
@@ -16,17 +16,17 @@ FactoryGirl.define do
trait
:cron_nightly_build
do
trait
:cron_nightly_build
do
cron
'0 1 * * *'
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
end
trait
:cron_weekly_build
do
trait
:cron_weekly_build
do
cron
'0 1 * * 6'
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
end
trait
:cron_monthly_build
do
trait
:cron_monthly_build
do
cron
'0 1 22 * *'
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
end
end
end
spec/helpers/triggers_helper_spec.rb
View file @
914bef67
...
@@ -11,7 +11,7 @@ describe TriggersHelper do
...
@@ -11,7 +11,7 @@ describe TriggersHelper do
let
(
:user_cron
)
{
'1 0 1 1 *'
}
# every 00:01, January 1st
let
(
:user_cron
)
{
'1 0 1 1 *'
}
# every 00:01, January 1st
it
'returns nearest worker_next_time from next_run_at'
do
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
))
.
next_time_from
(
trigger_schedule
.
next_run_at
))
end
end
end
end
...
@@ -21,7 +21,7 @@ describe TriggersHelper do
...
@@ -21,7 +21,7 @@ describe TriggersHelper do
let
(
:user_cron
)
{
'0 0 1 1 *'
}
# every 00:00, January 1st
let
(
:user_cron
)
{
'0 0 1 1 *'
}
# every 00:00, January 1st
it
'returns nearest worker_next_time from next_run_at'
do
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
))
.
next_time_from
(
trigger_schedule
.
next_run_at
))
end
end
end
end
...
@@ -31,7 +31,7 @@ describe TriggersHelper do
...
@@ -31,7 +31,7 @@ describe TriggersHelper do
let
(
:user_cron
)
{
'* * * * *'
}
# every minutes
let
(
:user_cron
)
{
'* * * * *'
}
# every minutes
it
'returns nearest worker_next_time from next_run_at by server configuration'
do
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
)
Time
.
zone
.
name
)
.
next_time_from
(
trigger_schedule
.
next_run_at
))
.
next_time_from
(
trigger_schedule
.
next_run_at
))
end
end
...
...
spec/models/ci/trigger_schedule_spec.rb
View file @
914bef67
...
@@ -13,7 +13,7 @@ describe Ci::TriggerSchedule, models: true do
...
@@ -13,7 +13,7 @@ describe Ci::TriggerSchedule, models: true do
end
end
it
'updates next_run_at'
do
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
)
expect
(
Ci
::
TriggerSchedule
.
last
.
next_run_at
).
to
eq
(
next_time
)
end
end
end
end
...
...
spec/workers/trigger_schedule_worker_spec.rb
View file @
914bef67
...
@@ -23,7 +23,7 @@ describe TriggerScheduleWorker do
...
@@ -23,7 +23,7 @@ describe TriggerScheduleWorker do
end
end
it
'updates next_run_at'
do
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
)
expect
(
Ci
::
TriggerSchedule
.
last
.
next_run_at
).
to
eq
(
next_time
)
end
end
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