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
056f1b70
Commit
056f1b70
authored
Feb 14, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify implementation of pipeline retry service
parent
94495f98
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
60 deletions
+41
-60
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+1
-7
app/services/ci/retry_pipeline_service.rb
app/services/ci/retry_pipeline_service.rb
+5
-37
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+4
-4
spec/services/ci/retry_pipeline_service_spec.rb
spec/services/ci/retry_pipeline_service_spec.rb
+31
-12
No files found.
app/models/ci/pipeline.rb
View file @
056f1b70
...
...
@@ -214,13 +214,7 @@ module Ci
def
cancel_running
Gitlab
::
OptimisticLocking
.
retry_lock
(
statuses
.
cancelable
)
do
|
cancelable
|
cancelable
.
each
do
|
status
|
if
status
.
created?
status
.
skip
elsif
status
.
active?
status
.
cancel
end
end
cancelable
.
find_each
(
&
:cancel
)
end
end
...
...
app/services/ci/retry_pipeline_service.rb
View file @
056f1b70
module
Ci
class
RetryPipelineService
<
::
BaseService
def
execute
(
pipeline
)
@pipeline
=
pipeline
unless
can?
(
current_user
,
:update_pipeline
,
pipeline
)
raise
Gitlab
::
Access
::
AccessDeniedError
end
pipeline
.
mark_as_processable_after_stage
(
resume_stage
.
index
)
each_build
(
pipeline
.
builds
.
failed_or_canceled
)
do
|
build
|
next
unless
build
.
retryable?
retryable_builds_in_subsequent_stages
do
|
build
|
Ci
::
RetryBuildService
.
new
(
project
,
current_user
)
.
reprocess
(
build
)
end
retryable_builds_in_first_unsuccessful_stage
do
|
build
|
Ci
::
RetryBuildService
.
new
(
project
,
current_user
)
.
retry
(
build
)
end
pipeline
.
process!
end
private
def
retryable_builds_in_subsequent_stages
relation
=
@pipeline
.
builds
.
after_stage
(
resume_stage
.
index
)
.
failed_or_canceled
each_retryable_build_with_locking
(
relation
)
do
|
build
|
yield
build
end
end
def
retryable_builds_in_first_unsuccessful_stage
relation
=
resume_stage
.
builds
.
failed_or_canceled
each_retryable_build_with_locking
(
relation
)
do
|
build
|
yield
build
end
end
def
each_retryable_build_with_locking
(
relation
)
def
each_build
(
relation
)
Gitlab
::
OptimisticLocking
.
retry_lock
(
relation
)
do
|
builds
|
builds
.
find_each
do
|
build
|
next
unless
build
.
retryable?
yield
build
end
end
end
def
resume_stage
@resume_stage
||=
@pipeline
.
stages
.
find
do
|
stage
|
stage
.
failed?
||
stage
.
canceled?
builds
.
find_each
{
|
build
|
yield
build
}
end
end
end
...
...
spec/models/ci/pipeline_spec.rb
View file @
056f1b70
...
...
@@ -766,8 +766,8 @@ describe Ci::Pipeline, models: true do
pipeline
.
cancel_running
end
it
'
skip
s created builds'
do
expect
(
latest_status
).
to
eq
[
'canceled'
,
'
skipp
ed'
]
it
'
cancel
s created builds'
do
expect
(
latest_status
).
to
eq
[
'canceled'
,
'
cancel
ed'
]
end
end
end
...
...
@@ -801,7 +801,7 @@ describe Ci::Pipeline, models: true do
end
it
'retries both builds'
do
expect
(
latest_status
).
to
contain_exactly
(
'pending'
,
'
pending
'
)
expect
(
latest_status
).
to
contain_exactly
(
'pending'
,
'
created
'
)
end
end
...
...
@@ -814,7 +814,7 @@ describe Ci::Pipeline, models: true do
end
it
'retries both builds'
do
expect
(
latest_status
).
to
contain_exactly
(
'pending'
,
'
pending
'
)
expect
(
latest_status
).
to
contain_exactly
(
'pending'
,
'
created
'
)
end
end
end
...
...
spec/services/ci/retry_pipeline_service_spec.rb
View file @
056f1b70
...
...
@@ -11,9 +11,9 @@ describe Ci::RetryPipelineService, '#execute', :services do
context
'when there are failed builds in the last stage'
do
before
do
create_build
(
name:
'rspec 1'
,
status: :success
,
stage_num:
0
)
create_build
(
name:
'rspec 2'
,
status: :failed
,
stage_num:
1
)
create_build
(
name:
'rspec 3'
,
status: :canceled
,
stage_num:
1
)
create_build
(
'rspec 1'
,
:success
,
0
)
create_build
(
'rspec 2'
,
:failed
,
1
)
create_build
(
'rspec 3'
,
:canceled
,
1
)
end
it
'enqueues all builds in the last stage'
do
...
...
@@ -27,10 +27,10 @@ describe Ci::RetryPipelineService, '#execute', :services do
context
'when there are failed or canceled builds in the first stage'
do
before
do
create_build
(
name:
'rspec 1'
,
status: :failed
,
stage_num:
0
)
create_build
(
name:
'rspec 2'
,
status: :canceled
,
stage_num:
0
)
create_build
(
name:
'rspec 3'
,
status: :skipped
,
stage_num:
1
)
create_build
(
name:
'deploy 1'
,
status: :skipped
,
stage_num:
2
)
create_build
(
'rspec 1'
,
:failed
,
0
)
create_build
(
'rspec 2'
,
:canceled
,
0
)
create_build
(
'rspec 3'
,
:canceled
,
1
)
create_build
(
'deploy 1'
,
:canceled
,
2
)
end
it
'retries builds failed builds and marks subsequent for processing'
do
...
...
@@ -46,10 +46,10 @@ describe Ci::RetryPipelineService, '#execute', :services do
context
'when there is failed build present which was run on failure'
do
before
do
create_build
(
name:
'rspec 1'
,
status: :failed
,
stage_num:
0
)
create_build
(
name:
'rspec 2'
,
status: :canceled
,
stage_num:
0
)
create_build
(
name:
'rspec 3'
,
status: :skipped
,
stage_num:
1
)
create_build
(
name:
'report 1'
,
status: :failed
,
stage_num:
2
)
create_build
(
'rspec 1'
,
:failed
,
0
)
create_build
(
'rspec 2'
,
:canceled
,
0
)
create_build
(
'rspec 3'
,
:canceled
,
1
)
create_build
(
'report 1'
,
:failed
,
2
)
end
it
'retries builds failed builds and marks subsequent for processing'
do
...
...
@@ -65,9 +65,27 @@ describe Ci::RetryPipelineService, '#execute', :services do
it
'creates a new job for report job in this case'
do
service
.
execute
(
pipeline
)
# TODO, expect to be_retried
expect
(
statuses
.
where
(
name:
'report 1'
).
count
).
to
eq
2
end
end
context
'when there is canceled manual build in first stage'
do
before
do
create_build
(
'rspec 1'
,
:failed
,
0
)
create_build
(
'staging'
,
:canceled
,
0
,
:manual
)
create_build
(
'rspec 2'
,
:canceled
,
1
)
end
it
'retries builds failed builds and marks subsequent for processing'
do
service
.
execute
(
pipeline
)
expect
(
build
(
'rspec 1'
)).
to
be_pending
expect
(
build
(
'staging'
)).
to
be_skipped
expect
(
build
(
'rspec 2'
)).
to
be_created
expect
(
pipeline
.
reload
).
to
be_running
end
end
end
context
'when user is not allowed to retry pipeline'
do
...
...
@@ -85,11 +103,12 @@ describe Ci::RetryPipelineService, '#execute', :services do
statuses
.
latest
.
find_by
(
name:
name
)
end
def
create_build
(
name
:,
status
:,
stage_num
:
)
def
create_build
(
name
,
status
,
stage_num
,
on
=
'on_success'
)
create
(
:ci_build
,
name:
name
,
status:
status
,
stage:
"stage_
#{
stage_num
}
"
,
stage_idx:
stage_num
,
when:
on
,
pipeline:
pipeline
)
do
|
build
|
pipeline
.
update_status
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