Commit 3e60d62c authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add class that handles pipeline creation sequence

parent 61dc0b7d
...@@ -20,25 +20,20 @@ module Ci ...@@ -20,25 +20,20 @@ module Ci
protected: project.protected_for?(ref) protected: project.protected_for?(ref)
) )
@pipeline.tap do |pipeline|
command = OpenStruct.new(ignore_skip_ci: ignore_skip_ci, command = OpenStruct.new(ignore_skip_ci: ignore_skip_ci,
save_incompleted: save_on_errors, save_incompleted: save_on_errors,
trigger_request: trigger_request,
schedule: schedule,
seeds_block: block, seeds_block: block,
project: project, project: project,
current_user: current_user) current_user: current_user)
sequence = SEQUENCE.map { |chain| chain.new(pipeline, command) }
sequence_complete = sequence.none? do |chain| sequence = Gitlab::Ci::Pipeline::Chain::Sequence
chain.perform! .new(pipeline, command, SEQUENCE)
chain.break?
end
sequence.build! do |pipeline, sequence|
update_merge_requests_head_pipeline if pipeline.persisted? update_merge_requests_head_pipeline if pipeline.persisted?
if sequence_complete if sequence.complete?
cancel_pending_pipelines if project.auto_cancel_pending_pipelines? cancel_pending_pipelines if project.auto_cancel_pending_pipelines?
pipeline_created_counter.increment(source: source) pipeline_created_counter.increment(source: source)
...@@ -49,6 +44,9 @@ module Ci ...@@ -49,6 +44,9 @@ module Ci
private private
def process_pipeline_sequence
end
def commit def commit
@commit ||= project.commit(origin_sha || origin_ref) @commit ||= project.commit(origin_sha || origin_ref)
end end
......
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
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