Extract CI/CD build retry code to separate service
This commit is contained in:
parent
4e3fc21217
commit
9202b1f4df
2 changed files with 44 additions and 26 deletions
|
@ -63,32 +63,7 @@ module Ci
|
|||
end
|
||||
|
||||
def retry(build, user = nil)
|
||||
new_build = 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,
|
||||
user: user,
|
||||
environment: build.environment,
|
||||
status_event: 'enqueue'
|
||||
)
|
||||
|
||||
MergeRequests::AddTodoWhenBuildFailsService
|
||||
.new(build.project, nil)
|
||||
.close(new_build)
|
||||
|
||||
build.pipeline.mark_as_processable_after_stage(build.stage_idx)
|
||||
new_build
|
||||
Ci::RetryBuildService.new(build, user).retry!
|
||||
end
|
||||
end
|
||||
|
||||
|
|
43
app/services/ci/retry_build_service.rb
Normal file
43
app/services/ci/retry_build_service.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
module Ci
|
||||
class RetryBuildService
|
||||
def initialize(build, user)
|
||||
@build = build
|
||||
@user = user
|
||||
@pipeline = build.pipeline
|
||||
end
|
||||
|
||||
def retry!
|
||||
clone_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
|
||||
|
||||
private
|
||||
|
||||
def clone_build
|
||||
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)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue