Commit 94495f98 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Use new pipeline retry service with optimistic locking

parent 346a7c69
...@@ -224,13 +224,9 @@ module Ci ...@@ -224,13 +224,9 @@ module Ci
end end
end end
def retry_failed(user) def retry_failed(current_user)
Gitlab::OptimisticLocking.retry_lock( Ci::RetryPipelineService.new(project, current_user)
builds.latest.failed_or_canceled) do |failed_or_canceled| .execute(self)
failed_or_canceled.select(&:retryable?).each do |build|
Ci::Build.retry(build, user)
end
end
end end
def mark_as_processable_after_stage(stage_idx) def mark_as_processable_after_stage(stage_idx)
......
module Ci module Ci
class RetryBuildService < ::BaseService class RetryBuildService < ::BaseService
def execute(build) def execute(build)
# return unless build.retryable?
self.retry(build).tap do |new_build| self.retry(build).tap do |new_build|
MergeRequests::AddTodoWhenBuildFailsService MergeRequests::AddTodoWhenBuildFailsService
.new(build.project, current_user) .new(build.project, current_user)
......
...@@ -7,34 +7,48 @@ module Ci ...@@ -7,34 +7,48 @@ module Ci
raise Gitlab::Access::AccessDeniedError raise Gitlab::Access::AccessDeniedError
end end
## pipeline.mark_as_processable_after_stage(resume_stage.index)
# Reprocess builds in subsequent stages
# retryable_builds_in_subsequent_stages do |build|
pipeline.builds Ci::RetryBuildService.new(project, current_user)
.after_stage(resume_stage.index)
.failed_or_canceled.find_each do |build|
Ci::RetryBuildService
.new(project, current_user)
.reprocess(build) .reprocess(build)
end end
## retryable_builds_in_first_unsuccessful_stage do |build|
# Mark skipped builds as processable again Ci::RetryBuildService.new(project, current_user)
#
pipeline.mark_as_processable_after_stage(resume_stage.index)
##
# Retry builds in the first unsuccessful stage
#
resume_stage.builds.failed_or_canceled.find_each do |build|
Ci::RetryBuildService
.new(project, current_user)
.retry(build) .retry(build)
end end
end end
private 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)
Gitlab::OptimisticLocking.retry_lock(relation) do |builds|
builds.find_each do |build|
next unless build.retryable?
yield build
end
end
end
def resume_stage def resume_stage
@resume_stage ||= @pipeline.stages.find do |stage| @resume_stage ||= @pipeline.stages.find do |stage|
stage.failed? || stage.canceled? stage.failed? || stage.canceled?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment