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
Léo-Paul Géneau
gitlab-ce
Commits
c0db4400
Commit
c0db4400
authored
Feb 14, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preserve base service abstraction for retry services
parent
21401a39
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
61 deletions
+62
-61
app/models/ci/build.rb
app/models/ci/build.rb
+3
-1
app/services/ci/retry_build_service.rb
app/services/ci/retry_build_service.rb
+29
-32
app/services/ci/retry_pipeline_service.rb
app/services/ci/retry_pipeline_service.rb
+16
-14
spec/services/ci/retry_build_service_spec.rb
spec/services/ci/retry_build_service_spec.rb
+8
-8
spec/services/ci/retry_pipeline_service_spec.rb
spec/services/ci/retry_pipeline_service_spec.rb
+6
-6
No files found.
app/models/ci/build.rb
View file @
c0db4400
...
...
@@ -63,7 +63,9 @@ module Ci
end
def
retry
(
build
,
current_user
)
Ci
::
RetryBuildService
.
new
(
build
,
current_user
).
retry!
Ci
::
RetryBuildService
.
new
(
build
.
project
,
current_user
)
.
execute
(
build
)
end
end
...
...
app/services/ci/retry_build_service.rb
View file @
c0db4400
module
Ci
class
RetryBuildService
include
Gitlab
::
Allowable
class
RetryBuildService
<
::
BaseService
def
execute
(
build
)
self
.
retry
(
build
).
tap
do
|
new_build
|
MergeRequests
::
AddTodoWhenBuildFailsService
.
new
(
build
.
project
,
current_user
)
.
close
(
new_build
)
def
initialize
(
build
,
user
)
@build
=
build
@user
=
user
@pipeline
=
build
.
pipeline
build
.
pipeline
.
mark_as_processable_after_stage
(
build
.
stage_idx
)
end
end
def
retry
!
reprocess!
.
tap
do
|
new_build
|
def
retry
(
build
)
self
.
reprocess
(
build
)
.
tap
do
|
new_build
|
new_build
.
enqueue!
MergeRequests
::
AddTodoWhenBuildFailsService
.
new
(
@build
.
project
,
@user
)
.
close
(
new_build
)
@pipeline
.
mark_as_processable_after_stage
(
@build
.
stage_idx
)
end
end
def
reprocess
!
unless
can?
(
@user
,
:update_build
,
@
build
)
def
reprocess
(
build
)
unless
can?
(
current_user
,
:update_build
,
build
)
raise
Gitlab
::
Access
::
AccessDeniedError
end
Ci
::
Build
.
create
(
ref:
@
build
.
ref
,
tag:
@
build
.
tag
,
options:
@
build
.
options
,
commands:
@
build
.
commands
,
tag_list:
@
build
.
tag_list
,
project:
@
build
.
project
,
pipeline:
@
build
.
pipeline
,
name:
@
build
.
name
,
allow_failure:
@
build
.
allow_failure
,
stage:
@
build
.
stage
,
stage_idx:
@
build
.
stage_idx
,
trigger_request:
@
build
.
trigger_request
,
yaml_variables:
@
build
.
yaml_variables
,
when:
@
build
.
when
,
environment:
@
build
.
environment
,
user:
@
user
)
ref:
build
.
ref
,
tag:
build
.
tag
,
options:
build
.
options
,
commands:
build
.
commands
,
tag_list:
build
.
tag_list
,
project:
build
.
project
,
pipeline:
build
.
pipeline
,
name:
build
.
name
,
allow_failure:
build
.
allow_failure
,
stage:
build
.
stage
,
stage_idx:
build
.
stage_idx
,
trigger_request:
build
.
trigger_request
,
yaml_variables:
build
.
yaml_variables
,
when:
build
.
when
,
environment:
build
.
environment
,
user:
current_
user
)
end
end
end
app/services/ci/retry_pipeline_service.rb
View file @
c0db4400
module
Ci
class
RetryPipelineService
include
Gitlab
::
Allowable
def
initialize
(
pipeline
,
user
)
class
RetryPipelineService
<
::
BaseService
def
execute
(
pipeline
)
@pipeline
=
pipeline
@user
=
user
end
def
execute
unless
can?
(
@user
,
:update_pipeline
,
@pipeline
)
unless
can?
(
current_user
,
:update_pipeline
,
pipeline
)
raise
Gitlab
::
Access
::
AccessDeniedError
end
##
# Reprocess builds in subsequent stages if any
#
# TODO, refactor.
# Reprocess builds in subsequent stages
#
@
pipeline
.
builds
pipeline
.
builds
.
where
(
'stage_idx > ?'
,
resume_stage
.
index
)
.
failed_or_canceled
.
find_each
do
|
build
|
Ci
::
RetryBuildService
.
new
(
build
,
@user
).
reprocess!
Ci
::
RetryBuildService
.
new
(
project
,
current_user
)
.
reprocess
(
build
)
end
##
# Retry builds in the first unsuccessful stage
#
resume_stage
.
builds
.
failed_or_canceled
.
find_each
do
|
build
|
Ci
::
Build
.
retry
(
build
,
@user
)
Ci
::
RetryBuildService
.
new
(
project
,
current_user
)
.
retry
(
build
)
end
##
# Mark skipped builds as processable again
#
pipeline
.
mark_as_processable_after_stage
(
resume_stage
.
index
)
end
private
...
...
spec/services/ci/retry_build_service_spec.rb
View file @
c0db4400
...
...
@@ -7,13 +7,13 @@ describe Ci::RetryBuildService, :services do
let
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
let
(
:service
)
do
described_class
.
new
(
build
,
user
)
described_class
.
new
(
project
,
user
)
end
describe
'#
retry!
'
do
let
(
:new_build
)
{
service
.
retry!
}
describe
'#
execute
'
do
let
(
:new_build
)
{
service
.
execute
(
build
)
}
context
'when user has ability to
retry
build'
do
context
'when user has ability to
execute
build'
do
before
do
project
.
team
<<
[
user
,
:developer
]
end
...
...
@@ -30,7 +30,7 @@ describe Ci::RetryBuildService, :services do
expect
(
MergeRequests
::
AddTodoWhenBuildFailsService
)
.
to
receive_message_chain
(
:new
,
:close
)
service
.
retry!
service
.
execute
(
build
)
end
context
'when there are subsequent builds that are skipped'
do
...
...
@@ -39,16 +39,16 @@ describe Ci::RetryBuildService, :services do
end
it
'resumes pipeline processing in subsequent stages'
do
service
.
retry!
service
.
execute
(
build
)
expect
(
subsequent_build
.
reload
).
to
be_created
end
end
end
context
'when user does not have ability to
retry
build'
do
context
'when user does not have ability to
execute
build'
do
it
'raises an error'
do
expect
{
service
.
retry!
}
expect
{
service
.
execute
(
build
)
}
.
to
raise_error
Gitlab
::
Access
::
AccessDeniedError
end
end
...
...
spec/services/ci/retry_pipeline_service_spec.rb
View file @
c0db4400
...
...
@@ -4,7 +4,7 @@ describe Ci::RetryPipelineService, '#execute', :services do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
let
(
:service
)
{
described_class
.
new
(
p
ipeline
,
user
)
}
let
(
:service
)
{
described_class
.
new
(
p
roject
,
user
)
}
context
'when user has ability to modify pipeline'
do
let
(
:user
)
{
create
(
:admin
)
}
...
...
@@ -17,7 +17,7 @@ describe Ci::RetryPipelineService, '#execute', :services do
end
it
'enqueues all builds in the last stage'
do
service
.
execute
service
.
execute
(
pipeline
)
expect
(
build
(
'rspec 2'
)).
to
be_pending
expect
(
build
(
'rspec 3'
)).
to
be_pending
...
...
@@ -34,7 +34,7 @@ describe Ci::RetryPipelineService, '#execute', :services do
end
it
'retries builds failed builds and marks subsequent for processing'
do
service
.
execute
service
.
execute
(
pipeline
)
expect
(
build
(
'rspec 1'
)).
to
be_pending
expect
(
build
(
'rspec 2'
)).
to
be_pending
...
...
@@ -53,7 +53,7 @@ describe Ci::RetryPipelineService, '#execute', :services do
end
it
'retries builds failed builds and marks subsequent for processing'
do
service
.
execute
service
.
execute
(
pipeline
)
expect
(
build
(
'rspec 1'
)).
to
be_pending
expect
(
build
(
'rspec 2'
)).
to
be_pending
...
...
@@ -63,7 +63,7 @@ describe Ci::RetryPipelineService, '#execute', :services do
end
it
'creates a new job for report job in this case'
do
service
.
execute
service
.
execute
(
pipeline
)
expect
(
statuses
.
where
(
name:
'report 1'
).
count
).
to
eq
2
end
...
...
@@ -72,7 +72,7 @@ describe Ci::RetryPipelineService, '#execute', :services do
context
'when user is not allowed to retry pipeline'
do
it
'raises an error'
do
expect
{
service
.
execute
}
expect
{
service
.
execute
(
pipeline
)
}
.
to
raise_error
Gitlab
::
Access
::
AccessDeniedError
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