diff options
| author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-09-26 11:13:40 +0200 |
|---|---|---|
| committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-09-26 11:13:40 +0200 |
| commit | 3e60d62cc39b512fa1ac6b419815e88a6f6e1224 (patch) | |
| tree | fc95d67609922d42fc84bc6b17af19caada65f89 | |
| parent | 61dc0b7dc7aeffc1b70bdde84864dccd90f7d655 (diff) | |
| download | gitlab-ce-3e60d62cc39b512fa1ac6b419815e88a6f6e1224.tar.gz | |
Add class that handles pipeline creation sequence
| -rw-r--r-- | app/services/ci/create_pipeline_service.rb | 30 | ||||
| -rw-r--r-- | lib/gitlab/ci/pipeline/chain/sequence.rb | 37 |
2 files changed, 51 insertions, 16 deletions
diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb index 0386c1e8829..b22904fa4f1 100644 --- a/app/services/ci/create_pipeline_service.rb +++ b/app/services/ci/create_pipeline_service.rb @@ -20,25 +20,20 @@ module Ci protected: project.protected_for?(ref) ) - @pipeline.tap do |pipeline| - command = OpenStruct.new(ignore_skip_ci: ignore_skip_ci, - save_incompleted: save_on_errors, - trigger_request: trigger_request, - schedule: schedule, - seeds_block: block, - project: project, - current_user: current_user) - - sequence = SEQUENCE.map { |chain| chain.new(pipeline, command) } - - sequence_complete = sequence.none? do |chain| - chain.perform! - chain.break? - end + command = OpenStruct.new(ignore_skip_ci: ignore_skip_ci, + save_incompleted: save_on_errors, + seeds_block: block, + project: project, + current_user: current_user) + + + sequence = Gitlab::Ci::Pipeline::Chain::Sequence + .new(pipeline, command, SEQUENCE) + sequence.build! do |pipeline, sequence| update_merge_requests_head_pipeline if pipeline.persisted? - if sequence_complete + if sequence.complete? cancel_pending_pipelines if project.auto_cancel_pending_pipelines? pipeline_created_counter.increment(source: source) @@ -49,6 +44,9 @@ module Ci private + def process_pipeline_sequence + end + def commit @commit ||= project.commit(origin_sha || origin_ref) end diff --git a/lib/gitlab/ci/pipeline/chain/sequence.rb b/lib/gitlab/ci/pipeline/chain/sequence.rb new file mode 100644 index 00000000000..e8d1ab36883 --- /dev/null +++ b/lib/gitlab/ci/pipeline/chain/sequence.rb @@ -0,0 +1,37 @@ +module Gitlab + module Ci + module Pipeline + module Chain + class Sequence + def initialize(pipeline, command, sequence) + @pipeline = pipeline + @completed = [] + + @sequence = sequence.map do |chain| + chain.new(pipeline, command) + end + end + + def build! + @sequence.each do |step| + step.perform! + + break if step.break? + + @completed << true + end + + @pipeline.tap do + yield @pipeline, self if block_given? + end + end + + def complete? + @completed.size == @sequence.size && + @completed.all? + end + end + end + end + end +end |
