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
Boxiang Sun
gitlab-ce
Commits
c426763c
Commit
c426763c
authored
Mar 29, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename ScheduledTrigger to TriggerSchedule. Because table structure changed.
parent
e32c1a5c
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
52 additions
and
23 deletions
+52
-23
app/models/ci/trigger.rb
app/models/ci/trigger.rb
+1
-0
app/models/ci/trigger_schedule.rb
app/models/ci/trigger_schedule.rb
+5
-5
app/workers/trigger_schedule_worker.rb
app/workers/trigger_schedule_worker.rb
+2
-3
config/gitlab.yml.example
config/gitlab.yml.example
+1
-1
config/initializers/1_settings.rb
config/initializers/1_settings.rb
+3
-3
spec/factories/ci/scheduled_triggers.rb
spec/factories/ci/scheduled_triggers.rb
+2
-3
spec/models/ci/trigger_schedule_spec.rb
spec/models/ci/trigger_schedule_spec.rb
+29
-0
spec/models/ci/trigger_spec.rb
spec/models/ci/trigger_spec.rb
+1
-0
spec/workers/trigger_schedule_worker_spec.rb
spec/workers/trigger_schedule_worker_spec.rb
+8
-8
No files found.
app/models/ci/trigger.rb
View file @
c426763c
...
...
@@ -8,6 +8,7 @@ module Ci
belongs_to
:owner
,
class_name:
"User"
has_many
:trigger_requests
,
dependent: :destroy
has_one
:trigger_schedule
,
dependent: :destroy
validates
:token
,
presence:
true
,
uniqueness:
true
...
...
app/models/ci/
scheduled_trigger
.rb
→
app/models/ci/
trigger_schedule
.rb
View file @
c426763c
module
Ci
class
ScheduledTrigger
<
ActiveRecord
::
Base
class
TriggerSchedule
<
ActiveRecord
::
Base
extend
Ci
::
Model
acts_as_paranoid
belongs_to
:project
belongs_to
:
owner
,
class_name:
"User"
belongs_to
:
trigger
def
schedule_next_run!
next_time
=
Ci
::
CronParser
.
new
(
cron
,
cron_time_zone
).
next_time_from_now
...
...
@@ -14,8 +14,8 @@ module Ci
end
end
def
update_last_run!
update_attributes
(
last_run_at:
Time
.
now
)
end
#
def update_last_run!
#
update_attributes(last_run_at: Time.now)
#
end
end
end
app/workers/
scheduled_trigger
_worker.rb
→
app/workers/
trigger_schedule
_worker.rb
View file @
c426763c
class
ScheduledTrigger
Worker
class
TriggerSchedule
Worker
include
Sidekiq
::
Worker
include
CronjobQueue
def
perform
Ci
::
ScheduledTrigger
.
where
(
"next_run_at < ?"
,
Time
.
now
).
find_each
do
|
trigger
|
Ci
::
TriggerSchedule
.
where
(
"next_run_at < ?"
,
Time
.
now
).
find_each
do
|
trigger
|
begin
Ci
::
CreatePipelineService
.
new
(
trigger
.
project
,
trigger
.
owner
,
ref:
trigger
.
ref
).
execute
(
ignore_skip_ci:
true
,
scheduled_trigger:
true
)
...
...
@@ -11,7 +11,6 @@ class ScheduledTriggerWorker
Rails
.
logger
.
error
"
#{
trigger
.
id
}
: Failed to trigger job:
#{
e
.
message
}
"
ensure
trigger
.
schedule_next_run!
trigger
.
update_last_run!
end
end
end
...
...
config/gitlab.yml.example
View file @
c426763c
...
...
@@ -181,7 +181,7 @@ production: &base
stuck_ci_jobs_worker:
cron: "0 * * * *"
# Execute scheduled triggers
scheduled_trigger
_worker:
trigger_schedule
_worker:
cron: "0 * * * *"
# Remove expired build artifacts
expire_build_artifacts_worker:
...
...
config/initializers/1_settings.rb
View file @
c426763c
...
...
@@ -315,9 +315,9 @@ Settings['cron_jobs'] ||= Settingslogic.new({})
Settings
.
cron_jobs
[
'stuck_ci_jobs_worker'
]
||=
Settingslogic
.
new
({})
Settings
.
cron_jobs
[
'stuck_ci_jobs_worker'
][
'cron'
]
||=
'0 * * * *'
Settings
.
cron_jobs
[
'stuck_ci_jobs_worker'
][
'job_class'
]
=
'StuckCiJobsWorker'
Settings
.
cron_jobs
[
'
scheduled_trigger
_worker'
]
||=
Settingslogic
.
new
({})
Settings
.
cron_jobs
[
'
scheduled_trigger
_worker'
][
'cron'
]
||=
'0 * * * *'
Settings
.
cron_jobs
[
'
scheduled_trigger_worker'
][
'job_class'
]
=
'ScheduledTrigger
Worker'
Settings
.
cron_jobs
[
'
trigger_schedule
_worker'
]
||=
Settingslogic
.
new
({})
Settings
.
cron_jobs
[
'
trigger_schedule
_worker'
][
'cron'
]
||=
'0 * * * *'
Settings
.
cron_jobs
[
'
trigger_schedule_worker'
][
'job_class'
]
=
'TriggerSchedule
Worker'
Settings
.
cron_jobs
[
'expire_build_artifacts_worker'
]
||=
Settingslogic
.
new
({})
Settings
.
cron_jobs
[
'expire_build_artifacts_worker'
][
'cron'
]
||=
'50 * * * *'
Settings
.
cron_jobs
[
'expire_build_artifacts_worker'
][
'job_class'
]
=
'ExpireBuildArtifactsWorker'
...
...
spec/factories/ci/scheduled_triggers.rb
View file @
c426763c
FactoryGirl
.
define
do
factory
:ci_
scheduled_trigger
,
class:
Ci
::
ScheduledTrigger
do
factory
:ci_
trigger_schedule
,
class:
Ci
::
TriggerSchedule
do
project
factory: :project
owner
factory: :user
ref
'master'
trigger
factory: :ci_trigger
trait
:force_triggable
do
next_run_at
Time
.
now
-
1
.
month
...
...
spec/models/ci/
scheduled_trigger
_spec.rb
→
spec/models/ci/
trigger_schedule
_spec.rb
View file @
c426763c
require
'spec_helper'
describe
Ci
::
ScheduledTrigger
,
models:
true
do
describe
Ci
::
TriggerSchedule
,
models:
true
do
describe
'associations'
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:
own
er
)
}
it
{
is_expected
.
to
belong_to
(
:
trigg
er
)
}
end
describe
'#schedule_next_run!'
do
subject
{
scheduled_trigger
.
schedule_next_run!
}
subject
{
trigger_schedule
.
schedule_next_run!
}
let
(
:
scheduled_trigger
)
{
create
(
:ci_scheduled_trigger
,
:cron_nightly_build
,
next_run_at:
nil
)
}
let
(
:
trigger_schedule
)
{
create
(
:ci_trigger_schedule
,
:cron_nightly_build
,
next_run_at:
nil
)
}
it
'updates next_run_at'
do
is_expected
.
not_to
be_nil
end
end
describe
'#update_last_run!'
do
subject
{
scheduled_trigger
.
update_last_run!
}
#
describe '#update_last_run!' do
#
subject { scheduled_trigger.update_last_run! }
let
(
:scheduled_trigger
)
{
create
(
:ci_scheduled_trigger
,
:cron_nightly_build
,
last_run_at:
nil
)
}
#
let(:scheduled_trigger) { create(:ci_scheduled_trigger, :cron_nightly_build, last_run_at: nil) }
it
'updates last_run_at'
do
is_expected
.
not_to
be_nil
end
end
#
it 'updates last_run_at' do
#
is_expected.not_to be_nil
#
end
#
end
end
spec/models/ci/trigger_spec.rb
View file @
c426763c
...
...
@@ -7,6 +7,7 @@ describe Ci::Trigger, models: true do
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:owner
)
}
it
{
is_expected
.
to
have_many
(
:trigger_requests
)
}
it
{
is_expected
.
to
have_one
(
:trigger_schedule
)
}
end
describe
'before_validation'
do
...
...
spec/workers/
scheduled_trigger
_worker_spec.rb
→
spec/workers/
trigger_schedule
_worker_spec.rb
View file @
c426763c
require
'spec_helper'
describe
ScheduledTrigger
Worker
do
describe
TriggerSchedule
Worker
do
let
(
:worker
)
{
described_class
.
new
}
before
do
...
...
@@ -9,7 +9,7 @@ describe ScheduledTriggerWorker do
context
'when there is a scheduled trigger within next_run_at'
do
before
do
create
(
:ci_
scheduled_trigger
,
:cron_nightly_build
,
:force_triggable
)
create
(
:ci_
trigger_schedule
,
:cron_nightly_build
,
:force_triggable
)
worker
.
perform
end
...
...
@@ -18,13 +18,13 @@ describe ScheduledTriggerWorker do
end
it
'schedules next_run_at'
do
scheduled_trigger2
=
create
(
:ci_scheduled_trigger
,
:cron_nightly_build
)
expect
(
Ci
::
ScheduledTrigger
.
last
.
next_run_at
).
to
eq
(
scheduled_trigger
2
.
next_run_at
)
trigger_schedule2
=
create
(
:ci_trigger_schedule
,
:cron_nightly_build
)
expect
(
Ci
::
TriggerSchedule
.
last
.
next_run_at
).
to
eq
(
trigger_schedule
2
.
next_run_at
)
end
end
context
'when there are no scheduled triggers within next_run_at'
do
let!
(
:
scheduled_trigger
)
{
create
(
:ci_scheduled_trigger
,
:cron_nightly_build
)
}
let!
(
:
trigger_schedule
)
{
create
(
:ci_trigger_schedule
,
:cron_nightly_build
)
}
before
do
worker
.
perform
...
...
@@ -35,12 +35,12 @@ describe ScheduledTriggerWorker do
end
it
'do not reschedule next_run_at'
do
expect
(
Ci
::
ScheduledTrigger
.
last
.
next_run_at
).
to
eq
(
scheduled_trigger
.
next_run_at
)
expect
(
Ci
::
TriggerSchedule
.
last
.
next_run_at
).
to
eq
(
trigger_schedule
.
next_run_at
)
end
end
context
'when next_run_at is nil'
do
let!
(
:
scheduled_trigger
)
{
create
(
:ci_scheduled_trigger
,
:cron_nightly_build
,
next_run_at:
nil
)
}
let!
(
:
trigger_schedule
)
{
create
(
:ci_trigger_schedule
,
:cron_nightly_build
,
next_run_at:
nil
)
}
before
do
worker
.
perform
...
...
@@ -51,7 +51,7 @@ describe ScheduledTriggerWorker do
end
it
'do not reschedule next_run_at'
do
expect
(
Ci
::
ScheduledTrigger
.
last
.
next_run_at
).
to
eq
(
scheduled_trigger
.
next_run_at
)
expect
(
Ci
::
TriggerSchedule
.
last
.
next_run_at
).
to
eq
(
trigger_schedule
.
next_run_at
)
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