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
4567e624
Commit
4567e624
authored
Sep 19, 2016
by
Kamil Trzcinski
Committed by
Grzegorz Bizon
Oct 03, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make pipeline processing asynchronous
Conflicts: app/models/ci/pipeline.rb app/models/commit_status.rb
parent
d9f9ad9d
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
51 additions
and
23 deletions
+51
-23
app/models/ci/build.rb
app/models/ci/build.rb
+1
-1
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+9
-2
app/models/commit_status.rb
app/models/commit_status.rb
+10
-4
app/services/merge_requests/add_todo_when_build_fails_service.rb
...vices/merge_requests/add_todo_when_build_fails_service.rb
+4
-4
app/services/merge_requests/base_service.rb
app/services/merge_requests/base_service.rb
+6
-9
app/services/merge_requests/merge_when_build_succeeds_service.rb
...vices/merge_requests/merge_when_build_succeeds_service.rb
+4
-3
app/workers/process_pipeline_worker.rb
app/workers/process_pipeline_worker.rb
+17
-0
No files found.
app/models/ci/build.rb
View file @
4567e624
...
@@ -67,7 +67,7 @@ module Ci
...
@@ -67,7 +67,7 @@ module Ci
environment:
build
.
environment
,
environment:
build
.
environment
,
status_event:
'enqueue'
status_event:
'enqueue'
)
)
MergeRequests
::
AddTodoWhenBuildFailsService
.
new
(
build
.
project
,
nil
).
close
(
new_build
)
MergeRequests
::
AddTodoWhenBuildFailsService
.
new
(
build
.
project
,
nil
).
close
(
new_build
.
pipeline
)
build
.
pipeline
.
mark_as_processable_after_stage
(
build
.
stage_idx
)
build
.
pipeline
.
mark_as_processable_after_stage
(
build
.
stage_idx
)
new_build
new_build
end
end
...
...
app/models/ci/pipeline.rb
View file @
4567e624
...
@@ -73,6 +73,14 @@ module Ci
...
@@ -73,6 +73,14 @@ module Ci
after_transition
do
|
pipeline
,
transition
|
after_transition
do
|
pipeline
,
transition
|
pipeline
.
execute_hooks
unless
transition
.
loopback?
pipeline
.
execute_hooks
unless
transition
.
loopback?
end
end
after_transition
[
:created
,
:pending
,
:running
]
=>
:success
do
|
pipeline
|
MergeRequests
::
MergeWhenBuildSucceedsService
.
new
(
pipeline
.
project
,
nil
).
trigger
(
pipeline
)
end
after_transition
any
=>
:failed
do
|
pipeline
|
MergeRequests
::
AddTodoWhenBuildFailsService
.
new
(
pipeline
.
project
,
nil
).
execute
(
pipeline
)
end
end
end
# ref can't be HEAD or SHA, can only be branch/tag name
# ref can't be HEAD or SHA, can only be branch/tag name
...
@@ -251,9 +259,8 @@ module Ci
...
@@ -251,9 +259,8 @@ module Ci
Ci
::
ProcessPipelineService
.
new
(
project
,
user
).
execute
(
self
)
Ci
::
ProcessPipelineService
.
new
(
project
,
user
).
execute
(
self
)
end
end
def
build_updated
def
update_status
with_lock
do
with_lock
do
reload
case
latest_builds_status
case
latest_builds_status
when
'pending'
then
enqueue
when
'pending'
then
enqueue
when
'running'
then
run
when
'running'
then
run
...
...
app/models/commit_status.rb
View file @
4567e624
...
@@ -74,10 +74,6 @@ class CommitStatus < ActiveRecord::Base
...
@@ -74,10 +74,6 @@ class CommitStatus < ActiveRecord::Base
true
true
end
end
after_transition
do
|
commit_status
,
transition
|
commit_status
.
pipeline
.
try
(
:build_updated
)
unless
transition
.
loopback?
end
after_transition
[
:created
,
:pending
,
:running
]
=>
:success
do
|
commit_status
|
after_transition
[
:created
,
:pending
,
:running
]
=>
:success
do
|
commit_status
|
MergeRequests
::
MergeWhenBuildSucceedsService
.
new
(
commit_status
.
pipeline
.
project
,
nil
).
trigger
(
commit_status
)
MergeRequests
::
MergeWhenBuildSucceedsService
.
new
(
commit_status
.
pipeline
.
project
,
nil
).
trigger
(
commit_status
)
end
end
...
@@ -85,6 +81,16 @@ class CommitStatus < ActiveRecord::Base
...
@@ -85,6 +81,16 @@ class CommitStatus < ActiveRecord::Base
after_transition
any
=>
:failed
do
|
commit_status
|
after_transition
any
=>
:failed
do
|
commit_status
|
MergeRequests
::
AddTodoWhenBuildFailsService
.
new
(
commit_status
.
pipeline
.
project
,
nil
).
execute
(
commit_status
)
MergeRequests
::
AddTodoWhenBuildFailsService
.
new
(
commit_status
.
pipeline
.
project
,
nil
).
execute
(
commit_status
)
end
end
after_transition
do
|
commit_status
,
transition
|
if
commit_status
.
pipeline
&&
!
transition
.
loopback?
ProcessPipelineWorker
.
perform_async
(
commit_status
.
pipeline
.
id
,
process:
HasStatus
.
COMPLETED_STATUSES
.
include?
(
commit_status
.
status
))
end
true
end
end
end
delegate
:sha
,
:short_sha
,
to: :pipeline
delegate
:sha
,
:short_sha
,
to: :pipeline
...
...
app/services/merge_requests/add_todo_when_build_fails_service.rb
View file @
4567e624
module
MergeRequests
module
MergeRequests
class
AddTodoWhenBuildFailsService
<
MergeRequests
::
BaseService
class
AddTodoWhenBuildFailsService
<
MergeRequests
::
BaseService
# Adds a todo to the parent merge_request when a CI build fails
# Adds a todo to the parent merge_request when a CI build fails
def
execute
(
commit_status
)
def
execute
(
pipeline
)
each_merge_request
(
commit_status
)
do
|
merge_request
|
each_merge_request
(
pipeline
)
do
|
merge_request
|
todo_service
.
merge_request_build_failed
(
merge_request
)
todo_service
.
merge_request_build_failed
(
merge_request
)
end
end
end
end
# Closes any pending build failed todos for the parent MRs when a build is retried
# Closes any pending build failed todos for the parent MRs when a build is retried
def
close
(
commit_status
)
def
close
(
pipeline
)
each_merge_request
(
commit_status
)
do
|
merge_request
|
each_merge_request
(
pipeline
)
do
|
merge_request
|
todo_service
.
merge_request_build_retried
(
merge_request
)
todo_service
.
merge_request_build_retried
(
merge_request
)
end
end
end
end
...
...
app/services/merge_requests/base_service.rb
View file @
4567e624
...
@@ -42,11 +42,11 @@ module MergeRequests
...
@@ -42,11 +42,11 @@ module MergeRequests
super
(
:merge_request
)
super
(
:merge_request
)
end
end
def
merge_request_from
(
commit_status
)
def
merge_request_from
(
pipeline
)
branches
=
commit_status
.
ref
branches
=
pipeline
.
ref
# This is for ref-less builds
# This is for ref-less builds
branches
||=
@project
.
repository
.
branch_names_contains
(
commit_status
.
sha
)
branches
||=
@project
.
repository
.
branch_names_contains
(
pipeline
.
sha
)
return
[]
if
branches
.
blank?
return
[]
if
branches
.
blank?
...
@@ -56,14 +56,11 @@ module MergeRequests
...
@@ -56,14 +56,11 @@ module MergeRequests
merge_requests
.
uniq
.
select
(
&
:source_project
)
merge_requests
.
uniq
.
select
(
&
:source_project
)
end
end
def
each_merge_request
(
commit_status
)
def
each_merge_request
(
pipeline
)
merge_request_from
(
commit_status
).
each
do
|
merge_request
|
merge_request_from
(
commit_status
).
each
do
|
merge_request
|
pipeline
=
merge_request
.
pipeline
next
unless
pipeline
=
=
merge_request
.
pipeline
next
unless
pipeline
yield
merge_request
next
unless
pipeline
.
sha
==
commit_status
.
sha
yield
merge_request
,
pipeline
end
end
end
end
end
end
...
...
app/services/merge_requests/merge_when_build_succeeds_service.rb
View file @
4567e624
...
@@ -19,11 +19,12 @@ module MergeRequests
...
@@ -19,11 +19,12 @@ module MergeRequests
end
end
# Triggers the automatic merge of merge_request once the build succeeds
# Triggers the automatic merge of merge_request once the build succeeds
def
trigger
(
commit_status
)
def
trigger
(
pipeline
)
each_merge_request
(
commit_status
)
do
|
merge_request
,
pipeline
|
return
unless
pipeline
.
success?
each_merge_request
(
pipeline
)
do
|
merge_request
|
next
unless
merge_request
.
merge_when_build_succeeds?
next
unless
merge_request
.
merge_when_build_succeeds?
next
unless
merge_request
.
mergeable?
next
unless
merge_request
.
mergeable?
next
unless
pipeline
.
success?
MergeWorker
.
perform_async
(
merge_request
.
id
,
merge_request
.
merge_user_id
,
merge_request
.
merge_params
)
MergeWorker
.
perform_async
(
merge_request
.
id
,
merge_request
.
merge_user_id
,
merge_request
.
merge_params
)
end
end
...
...
app/workers/process_pipeline_worker.rb
0 → 100644
View file @
4567e624
class
ProcessPipelineWorker
include
Sidekiq
::
Worker
sidekiq_options
queue: :default
def
perform
(
pipeline_id
,
params
)
begin
pipeline
=
Ci
::
Pipeline
.
find
(
pipeline_id
)
rescue
ActiveRecord
::
RecordNotFound
return
end
pipeline
.
process!
if
params
[
:process
]
pipeline
.
update_status
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