diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2016-11-30 11:16:53 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2016-11-30 11:16:53 +0000 |
commit | 7e5fa10b665835e3160eee4d333a17fbaef9c113 (patch) | |
tree | 4b5515119134b0ca92bc1f73b13ab19e4361be03 /app | |
parent | 21b90ef8668ef888ff64e5a0f1a9c1b26ff0fccc (diff) | |
parent | 3761a0c50ea13b86152417a5e659b30879cb16b1 (diff) | |
download | gitlab-ce-7e5fa10b665835e3160eee4d333a17fbaef9c113.tar.gz |
Merge branch 'fix/create-pipeline-with-builds-in-transaction' into 'master'
Create pipeline along with builds in the transation
## What does this MR do?
This MR makes it possible to create pipeline along with all associated builds in the transaction, to avoid having empty pipelines when asynchronous job gets terminated.
This will simplify implementation of `PipelineUnlockWorker` in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6988 and improve reliability of the CI as a whole.
## What are the relevant issue numbers?
Related to #24361
See merge request !7742
Diffstat (limited to 'app')
-rw-r--r-- | app/services/ci/create_pipeline_service.rb | 12 | ||||
-rw-r--r-- | app/services/ci/process_pipeline_service.rb | 22 |
2 files changed, 23 insertions, 11 deletions
diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb index cde856b0186..e3bc9847200 100644 --- a/app/services/ci/create_pipeline_service.rb +++ b/app/services/ci/create_pipeline_service.rb @@ -45,9 +45,15 @@ module Ci return error('No builds for this pipeline.') end - pipeline.save - pipeline.process! - pipeline + Ci::Pipeline.transaction do + pipeline.save + + Ci::CreatePipelineBuildsService + .new(project, current_user) + .execute(pipeline) + end + + pipeline.tap(&:process!) end private diff --git a/app/services/ci/process_pipeline_service.rb b/app/services/ci/process_pipeline_service.rb index 8face432d97..2e028c44d8b 100644 --- a/app/services/ci/process_pipeline_service.rb +++ b/app/services/ci/process_pipeline_service.rb @@ -5,10 +5,7 @@ module Ci def execute(pipeline) @pipeline = pipeline - # This method will ensure that our pipeline does have all builds for all stages created - if created_builds.empty? - create_builds! - end + ensure_created_builds! # TODO, remove me in 9.0 new_builds = stage_indexes_of_created_builds.map do |index| @@ -22,10 +19,6 @@ module Ci private - def create_builds! - Ci::CreatePipelineBuildsService.new(project, current_user).execute(pipeline) - end - def process_stage(index) current_status = status_for_prior_stages(index) @@ -76,5 +69,18 @@ module Ci def created_builds pipeline.builds.created end + + # This method is DEPRECATED and should be removed in 9.0. + # + # We need it to maintain backwards compatibility with previous versions + # when builds were not created within one transaction with the pipeline. + # + def ensure_created_builds! + return if created_builds.any? + + Ci::CreatePipelineBuildsService + .new(project, current_user) + .execute(pipeline) + end end end |