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
61dc0b7d
Commit
61dc0b7d
authored
Sep 26, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract pipeline persistence to a separate chain class
parent
7cfaccd6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
32 deletions
+50
-32
app/services/ci/create_pipeline_service.rb
app/services/ci/create_pipeline_service.rb
+21
-32
lib/gitlab/ci/pipeline/chain/create.rb
lib/gitlab/ci/pipeline/chain/create.rb
+29
-0
No files found.
app/services/ci/create_pipeline_service.rb
View file @
61dc0b7d
...
@@ -3,9 +3,10 @@ module Ci
...
@@ -3,9 +3,10 @@ module Ci
attr_reader
:pipeline
attr_reader
:pipeline
SEQUENCE
=
[
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Validate
,
SEQUENCE
=
[
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Validate
,
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Skip
].
freeze
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Skip
,
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Create
].
freeze
def
execute
(
source
,
ignore_skip_ci:
false
,
save_on_errors:
true
,
trigger_request:
nil
,
schedule:
nil
)
def
execute
(
source
,
ignore_skip_ci:
false
,
save_on_errors:
true
,
trigger_request:
nil
,
schedule:
nil
,
&
block
)
@pipeline
=
Ci
::
Pipeline
.
new
(
@pipeline
=
Ci
::
Pipeline
.
new
(
source:
source
,
source:
source
,
project:
project
,
project:
project
,
...
@@ -19,43 +20,31 @@ module Ci
...
@@ -19,43 +20,31 @@ module Ci
protected:
project
.
protected_for?
(
ref
)
protected:
project
.
protected_for?
(
ref
)
)
)
command
=
OpenStruct
.
new
(
ignore_skip_ci:
ignore_skip_ci
,
@pipeline
.
tap
do
|
pipeline
|
save_incompleted:
save_on_errors
,
command
=
OpenStruct
.
new
(
ignore_skip_ci:
ignore_skip_ci
,
trigger_request:
trigger_request
,
save_incompleted:
save_on_errors
,
schedule:
schedule
,
trigger_request:
trigger_request
,
project:
project
,
schedule:
schedule
,
current_user:
current_user
)
seeds_block:
block
,
project:
project
,
current_user:
current_user
)
sequence
=
SEQUENCE
.
map
{
|
chain
|
chain
.
new
(
pipeline
,
command
)
}
sequence
=
SEQUENCE
.
map
{
|
chain
|
chain
.
new
(
pipeline
,
command
)
}
done
=
sequence
.
any?
do
|
chain
|
sequence_complete
=
sequence
.
none?
do
|
chain
|
chain
.
perform!
chain
.
perform!
chain
.
break?
chain
.
break?
end
end
update_merge_requests_head_pipeline
if
pipeline
.
persisted?
return
pipeline
if
done
begin
update_merge_requests_head_pipeline
if
pipeline
.
persisted?
Ci
::
Pipeline
.
transaction
do
pipeline
.
save!
yield
(
pipeline
)
if
block_given?
if
sequence_complete
cancel_pending_pipelines
if
project
.
auto_cancel_pending_pipelines?
pipeline_created_counter
.
increment
(
source:
source
)
Ci
::
CreatePipelineStagesService
pipeline
.
process!
.
new
(
project
,
current_user
)
.
execute
(
pipeline
)
end
end
rescue
ActiveRecord
::
RecordInvalid
=>
e
return
error
(
"Failed to persist the pipeline:
#{
e
}
"
)
end
end
update_merge_requests_head_pipeline
if
pipeline
.
persisted?
cancel_pending_pipelines
if
project
.
auto_cancel_pending_pipelines?
pipeline_created_counter
.
increment
(
source:
source
)
pipeline
.
tap
(
&
:process!
)
end
end
private
private
...
...
lib/gitlab/ci/pipeline/chain/create.rb
0 → 100644
View file @
61dc0b7d
module
Gitlab
module
Ci
module
Pipeline
module
Chain
class
Create
<
Chain
::
Base
def
perform!
::
Ci
::
Pipeline
.
transaction
do
pipeline
.
save!
if
@command
.
seeds_block
@command
.
seeds_block
.
call
(
pipeline
)
end
::
Ci
::
CreatePipelineStagesService
.
new
(
project
,
current_user
)
.
execute
(
pipeline
)
end
rescue
ActiveRecord
::
RecordInvalid
=>
e
pipeline
.
erros
.
add
(
:base
,
"Failed to persist the pipeline:
#{
e
}
"
)
end
def
break?
!
pipeline
.
persisted?
end
end
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