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
Jérome Perrin
gitlab-ce
Commits
4688eb47
Commit
4688eb47
authored
Apr 05, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename cron_time_zone to cron_timezone. Separate add_concurrent_foreign_key.
parent
1dbc888e
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
56 additions
and
49 deletions
+56
-49
app/models/ci/trigger_schedule.rb
app/models/ci/trigger_schedule.rb
+2
-2
app/validators/cron_timezone_validator.rb
app/validators/cron_timezone_validator.rb
+5
-5
app/validators/cron_validator.rb
app/validators/cron_validator.rb
+1
-1
db/migrate/20170329095907_create_ci_trigger_schedules.rb
db/migrate/20170329095907_create_ci_trigger_schedules.rb
+4
-12
db/migrate/20170404163427_add_trigger_id_foreign_key.rb
db/migrate/20170404163427_add_trigger_id_foreign_key.rb
+15
-0
db/schema.rb
db/schema.rb
+1
-1
lib/gitlab/ci/cron_parser.rb
lib/gitlab/ci/cron_parser.rb
+7
-7
spec/factories/ci/trigger_schedules.rb
spec/factories/ci/trigger_schedules.rb
+4
-4
spec/lib/gitlab/ci/cron_parser_spec.rb
spec/lib/gitlab/ci/cron_parser_spec.rb
+14
-14
spec/lib/gitlab/import_export/safe_model_attributes.yml
spec/lib/gitlab/import_export/safe_model_attributes.yml
+1
-1
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/models/ci/trigger_schedule.rb
View file @
4688eb47
...
@@ -12,13 +12,13 @@ module Ci
...
@@ -12,13 +12,13 @@ module Ci
validates
:trigger
,
presence:
{
unless: :importing?
}
validates
:trigger
,
presence:
{
unless: :importing?
}
validates
:cron
,
cron:
true
,
presence:
{
unless: :importing?
}
validates
:cron
,
cron:
true
,
presence:
{
unless: :importing?
}
validates
:cron_time
_zone
,
cron_time_
zone:
true
,
presence:
{
unless: :importing?
}
validates
:cron_time
zone
,
cron_time
zone:
true
,
presence:
{
unless: :importing?
}
validates
:ref
,
presence:
{
unless: :importing?
}
validates
:ref
,
presence:
{
unless: :importing?
}
after_create
:schedule_next_run!
after_create
:schedule_next_run!
def
schedule_next_run!
def
schedule_next_run!
next_time
=
Gitlab
::
Ci
::
CronParser
.
new
(
cron
,
cron_time
_
zone
).
next_time_from
(
Time
.
now
)
next_time
=
Gitlab
::
Ci
::
CronParser
.
new
(
cron
,
cron_timezone
).
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_time
_
zone_validator.rb
→
app/validators/cron_timezone_validator.rb
View file @
4688eb47
# CronTime
Z
oneValidator
# CronTime
z
oneValidator
#
#
# Custom validator for CronTime
Z
one.
# Custom validator for CronTime
z
one.
class
CronTime
Z
oneValidator
<
ActiveModel
::
EachValidator
class
CronTime
z
oneValidator
<
ActiveModel
::
EachValidator
def
validate_each
(
record
,
attribute
,
value
)
def
validate_each
(
record
,
attribute
,
value
)
cron_parser
=
Gitlab
::
Ci
::
CronParser
.
new
(
record
.
cron
,
record
.
cron_time
_
zone
)
cron_parser
=
Gitlab
::
Ci
::
CronParser
.
new
(
record
.
cron
,
record
.
cron_timezone
)
record
.
errors
.
add
(
attribute
,
" is invalid syntax"
)
unless
cron_parser
.
cron_time
_
zone_valid?
record
.
errors
.
add
(
attribute
,
" is invalid syntax"
)
unless
cron_parser
.
cron_timezone_valid?
end
end
end
end
app/validators/cron_validator.rb
View file @
4688eb47
...
@@ -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
=
Gitlab
::
Ci
::
CronParser
.
new
(
record
.
cron
,
record
.
cron_time
_
zone
)
cron_parser
=
Gitlab
::
Ci
::
CronParser
.
new
(
record
.
cron
,
record
.
cron_timezone
)
record
.
errors
.
add
(
attribute
,
" is invalid syntax"
)
unless
cron_parser
.
cron_valid?
record
.
errors
.
add
(
attribute
,
" is invalid syntax"
)
unless
cron_parser
.
cron_valid?
end
end
end
end
db/migrate/20170329095907_create_ci_trigger_schedules.rb
View file @
4688eb47
...
@@ -3,9 +3,7 @@ class CreateCiTriggerSchedules < ActiveRecord::Migration
...
@@ -3,9 +3,7 @@ class CreateCiTriggerSchedules < ActiveRecord::Migration
DOWNTIME
=
false
DOWNTIME
=
false
disable_ddl_transaction!
def
change
def
up
create_table
:ci_trigger_schedules
do
|
t
|
create_table
:ci_trigger_schedules
do
|
t
|
t
.
integer
"project_id"
t
.
integer
"project_id"
t
.
integer
"trigger_id"
,
null:
false
t
.
integer
"trigger_id"
,
null:
false
...
@@ -13,17 +11,11 @@ class CreateCiTriggerSchedules < ActiveRecord::Migration
...
@@ -13,17 +11,11 @@ class CreateCiTriggerSchedules < ActiveRecord::Migration
t
.
datetime
"created_at"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
t
.
string
"cron"
t
.
string
"cron"
t
.
string
"cron_time
_
zone"
t
.
string
"cron_timezone"
t
.
datetime
"next_run_at"
t
.
datetime
"next_run_at"
end
end
add_index
:ci_trigger_schedules
,
[
"next_run_at"
],
name:
"index_ci_trigger_schedules_on_next_run_at"
,
using: :btree
add_index
:ci_trigger_schedules
,
:next_run_at
add_index
:ci_trigger_schedules
,
[
"project_id"
],
name:
"index_ci_trigger_schedules_on_project_id"
,
using: :btree
add_index
:ci_trigger_schedules
,
:project_id
add_concurrent_foreign_key
:ci_trigger_schedules
,
:ci_triggers
,
column: :trigger_id
,
on_delete: :cascade
end
def
down
remove_foreign_key
:ci_trigger_schedules
,
column: :trigger_id
drop_table
:ci_trigger_schedules
end
end
end
end
db/migrate/20170404163427_add_trigger_id_foreign_key.rb
0 → 100644
View file @
4688eb47
class
AddTriggerIdForeignKey
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
add_concurrent_foreign_key
:ci_trigger_schedules
,
:ci_triggers
,
column: :trigger_id
,
on_delete: :cascade
end
def
down
remove_foreign_key
:ci_trigger_schedules
,
column: :trigger_id
end
end
db/schema.rb
View file @
4688eb47
...
@@ -307,7 +307,7 @@ ActiveRecord::Schema.define(version: 20170405080720) do
...
@@ -307,7 +307,7 @@ ActiveRecord::Schema.define(version: 20170405080720) do
t
.
datetime
"created_at"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
t
.
string
"cron"
t
.
string
"cron"
t
.
string
"cron_time
_
zone"
t
.
string
"cron_timezone"
t
.
datetime
"next_run_at"
t
.
datetime
"next_run_at"
end
end
...
...
lib/gitlab/ci/cron_parser.rb
View file @
4688eb47
...
@@ -4,13 +4,13 @@ module Gitlab
...
@@ -4,13 +4,13 @@ module Gitlab
VALID_SYNTAX_SAMPLE_TIME_ZONE
=
'UTC'
.
freeze
VALID_SYNTAX_SAMPLE_TIME_ZONE
=
'UTC'
.
freeze
VALID_SYNTAX_SAMPLE_CRON
=
'* * * * *'
.
freeze
VALID_SYNTAX_SAMPLE_CRON
=
'* * * * *'
.
freeze
def
initialize
(
cron
,
cron_time
_
zone
=
'UTC'
)
def
initialize
(
cron
,
cron_timezone
=
'UTC'
)
@cron
=
cron
@cron
=
cron
@cron_time
_zone
=
cron_time_
zone
@cron_time
zone
=
cron_time
zone
end
end
def
next_time_from
(
time
)
def
next_time_from
(
time
)
cron_line
=
try_parse_cron
(
@cron
,
@cron_time
_
zone
)
cron_line
=
try_parse_cron
(
@cron
,
@cron_timezone
)
cron_line
.
next_time
(
time
).
in_time_zone
(
Time
.
zone
)
if
cron_line
.
present?
cron_line
.
next_time
(
time
).
in_time_zone
(
Time
.
zone
)
if
cron_line
.
present?
end
end
...
@@ -18,14 +18,14 @@ module Gitlab
...
@@ -18,14 +18,14 @@ module Gitlab
try_parse_cron
(
@cron
,
VALID_SYNTAX_SAMPLE_TIME_ZONE
).
present?
try_parse_cron
(
@cron
,
VALID_SYNTAX_SAMPLE_TIME_ZONE
).
present?
end
end
def
cron_time
_
zone_valid?
def
cron_timezone_valid?
try_parse_cron
(
VALID_SYNTAX_SAMPLE_CRON
,
@cron_time
_
zone
).
present?
try_parse_cron
(
VALID_SYNTAX_SAMPLE_CRON
,
@cron_timezone
).
present?
end
end
private
private
def
try_parse_cron
(
cron
,
cron_time
_
zone
)
def
try_parse_cron
(
cron
,
cron_timezone
)
Rufus
::
Scheduler
.
parse
(
"
#{
cron
}
#{
cron_time
_
zone
}
"
)
Rufus
::
Scheduler
.
parse
(
"
#{
cron
}
#{
cron_timezone
}
"
)
rescue
rescue
# noop
# noop
end
end
...
...
spec/factories/ci/trigger_schedules.rb
View file @
4688eb47
...
@@ -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
Gitlab
::
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_TIME_ZONE
cron_timezone
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
:nightly
do
trait
:nightly
do
cron
'0 1 * * *'
cron
'0 1 * * *'
cron_time
_
zone
Gitlab
::
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_TIME_ZONE
cron_timezone
Gitlab
::
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_TIME_ZONE
end
end
trait
:weekly
do
trait
:weekly
do
cron
'0 1 * * 6'
cron
'0 1 * * 6'
cron_time
_
zone
Gitlab
::
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_TIME_ZONE
cron_timezone
Gitlab
::
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_TIME_ZONE
end
end
trait
:monthly
do
trait
:monthly
do
cron
'0 1 22 * *'
cron
'0 1 22 * *'
cron_time
_
zone
Gitlab
::
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_TIME_ZONE
cron_timezone
Gitlab
::
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_TIME_ZONE
end
end
end
end
end
end
spec/lib/gitlab/ci/cron_parser_spec.rb
View file @
4688eb47
...
@@ -6,12 +6,12 @@ describe Gitlab::Ci::CronParser do
...
@@ -6,12 +6,12 @@ describe Gitlab::Ci::CronParser do
end
end
describe
'#next_time_from'
do
describe
'#next_time_from'
do
subject
{
described_class
.
new
(
cron
,
cron_time
_
zone
).
next_time_from
(
Time
.
now
)
}
subject
{
described_class
.
new
(
cron
,
cron_timezone
).
next_time_from
(
Time
.
now
)
}
context
'when cron and cron_time
_
zone are valid'
do
context
'when cron and cron_timezone are valid'
do
context
'when specific time'
do
context
'when specific time'
do
let
(
:cron
)
{
'3 4 5 6 *'
}
let
(
:cron
)
{
'3 4 5 6 *'
}
let
(
:cron_time
_
zone
)
{
'UTC'
}
let
(
:cron_timezone
)
{
'UTC'
}
it_behaves_like
"returns time in the future"
it_behaves_like
"returns time in the future"
...
@@ -25,7 +25,7 @@ describe Gitlab::Ci::CronParser do
...
@@ -25,7 +25,7 @@ describe Gitlab::Ci::CronParser do
context
'when specific day of week'
do
context
'when specific day of week'
do
let
(
:cron
)
{
'* * * * 0'
}
let
(
:cron
)
{
'* * * * 0'
}
let
(
:cron_time
_
zone
)
{
'UTC'
}
let
(
:cron_timezone
)
{
'UTC'
}
it_behaves_like
"returns time in the future"
it_behaves_like
"returns time in the future"
...
@@ -36,7 +36,7 @@ describe Gitlab::Ci::CronParser do
...
@@ -36,7 +36,7 @@ describe Gitlab::Ci::CronParser do
context
'when slash used'
do
context
'when slash used'
do
let
(
:cron
)
{
'*/10 */6 */10 */10 *'
}
let
(
:cron
)
{
'*/10 */6 */10 */10 *'
}
let
(
:cron_time
_
zone
)
{
'UTC'
}
let
(
:cron_timezone
)
{
'UTC'
}
it_behaves_like
"returns time in the future"
it_behaves_like
"returns time in the future"
...
@@ -50,7 +50,7 @@ describe Gitlab::Ci::CronParser do
...
@@ -50,7 +50,7 @@ describe Gitlab::Ci::CronParser do
context
'when range used'
do
context
'when range used'
do
let
(
:cron
)
{
'0,20,40 * 1-5 * *'
}
let
(
:cron
)
{
'0,20,40 * 1-5 * *'
}
let
(
:cron_time
_
zone
)
{
'UTC'
}
let
(
:cron_timezone
)
{
'UTC'
}
it_behaves_like
"returns time in the future"
it_behaves_like
"returns time in the future"
...
@@ -60,9 +60,9 @@ describe Gitlab::Ci::CronParser do
...
@@ -60,9 +60,9 @@ describe Gitlab::Ci::CronParser do
end
end
end
end
context
'when cron_time
_
zone is US/Pacific'
do
context
'when cron_timezone is US/Pacific'
do
let
(
:cron
)
{
'0 0 * * *'
}
let
(
:cron
)
{
'0 0 * * *'
}
let
(
:cron_time
_
zone
)
{
'US/Pacific'
}
let
(
:cron_timezone
)
{
'US/Pacific'
}
it_behaves_like
"returns time in the future"
it_behaves_like
"returns time in the future"
...
@@ -72,9 +72,9 @@ describe Gitlab::Ci::CronParser do
...
@@ -72,9 +72,9 @@ describe Gitlab::Ci::CronParser do
end
end
end
end
context
'when cron and cron_time
_
zone are invalid'
do
context
'when cron and cron_timezone are invalid'
do
let
(
:cron
)
{
'invalid_cron'
}
let
(
:cron
)
{
'invalid_cron'
}
let
(
:cron_time
_zone
)
{
'invalid_cron_time_
zone'
}
let
(
:cron_time
zone
)
{
'invalid_cron_time
zone'
}
it
'returns nil'
do
it
'returns nil'
do
is_expected
.
to
be_nil
is_expected
.
to
be_nil
...
@@ -98,17 +98,17 @@ describe Gitlab::Ci::CronParser do
...
@@ -98,17 +98,17 @@ describe Gitlab::Ci::CronParser do
end
end
end
end
describe
'#cron_time
_
zone_valid?'
do
describe
'#cron_timezone_valid?'
do
subject
{
described_class
.
new
(
Gitlab
::
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_CRON
,
cron_time
_zone
).
cron_time_
zone_valid?
}
subject
{
described_class
.
new
(
Gitlab
::
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_CRON
,
cron_time
zone
).
cron_time
zone_valid?
}
context
'when cron is valid'
do
context
'when cron is valid'
do
let
(
:cron_time
_
zone
)
{
'Europe/Istanbul'
}
let
(
:cron_timezone
)
{
'Europe/Istanbul'
}
it
{
is_expected
.
to
eq
(
true
)
}
it
{
is_expected
.
to
eq
(
true
)
}
end
end
context
'when cron is invalid'
do
context
'when cron is invalid'
do
let
(
:cron_time
_
zone
)
{
'Invalid-zone'
}
let
(
:cron_timezone
)
{
'Invalid-zone'
}
it
{
is_expected
.
to
eq
(
false
)
}
it
{
is_expected
.
to
eq
(
false
)
}
end
end
...
...
spec/lib/gitlab/import_export/safe_model_attributes.yml
View file @
4688eb47
...
@@ -249,7 +249,7 @@ Ci::TriggerSchedule:
...
@@ -249,7 +249,7 @@ Ci::TriggerSchedule:
-
created_at
-
created_at
-
updated_at
-
updated_at
-
cron
-
cron
-
cron_time
_
zone
-
cron_timezone
-
next_run_at
-
next_run_at
DeployKey
:
DeployKey
:
-
id
-
id
...
...
spec/models/ci/trigger_schedule_spec.rb
View file @
4688eb47
...
@@ -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
=
Gitlab
::
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_timezone
).
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 @
4688eb47
...
@@ -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
=
Gitlab
::
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_timezone
).
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