2017-02-13 14:14:40 +00:00
|
|
|
module Ci
|
2017-02-14 09:38:17 +00:00
|
|
|
class RetryPipelineService < ::BaseService
|
|
|
|
def execute(pipeline)
|
|
|
|
unless can?(current_user, :update_pipeline, pipeline)
|
2017-02-13 14:14:40 +00:00
|
|
|
raise Gitlab::Access::AccessDeniedError
|
|
|
|
end
|
|
|
|
|
2017-02-14 12:29:58 +00:00
|
|
|
each_build(pipeline.builds.failed_or_canceled) do |build|
|
|
|
|
next unless build.retryable?
|
2017-02-14 10:38:19 +00:00
|
|
|
|
2017-02-14 11:20:02 +00:00
|
|
|
Ci::RetryBuildService.new(project, current_user)
|
|
|
|
.reprocess(build)
|
|
|
|
end
|
|
|
|
|
2017-02-14 12:29:58 +00:00
|
|
|
pipeline.process!
|
2017-02-13 15:38:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-02-14 12:29:58 +00:00
|
|
|
def each_build(relation)
|
2017-02-14 11:20:02 +00:00
|
|
|
Gitlab::OptimisticLocking.retry_lock(relation) do |builds|
|
2017-02-14 12:29:58 +00:00
|
|
|
builds.find_each { |build| yield build }
|
2017-02-13 14:14:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|