diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index e75fe6c222bf7dd37cf91e61f438b4a9f0b0e839..aa493ef6fadeda74c6fd1dcfd6c8fc6b57f09442 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -104,6 +104,22 @@ def self.total_duration where.not(duration: nil).sum(:duration) end + def update_events_key + "#{id}_suppress_update_events" + end + + def are_update_events_suppressed? + Thread.current[update_events_key].to_i > 0 + end + + def suppress_update_events + Thread.current[update_events_key] ||= 0 + Thread.current[update_events_key] += 1 + yield + ensure + Thread.current[update_events_key] -= 1 + end + def stages_with_latest_statuses statuses.latest.includes(project: :namespace).order(:stage_idx).group_by(&:stage) end @@ -173,7 +189,9 @@ def retry_failed(user) end def mark_as_processable_after_stage(stage_idx) - builds.skipped.where('stage_idx > ?', stage_idx).find_each(&:process) + suppress_update_events do + builds.skipped.where('stage_idx > ?', stage_idx).find_each(&:process) + end end def latest? diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index 7b554be4f9a586bc61459e1d6766b2d5b63fadf4..b9e3d6bee533b0019d7b3de78a49b0b6e1d82a09 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -90,10 +90,12 @@ class CommitStatus < ActiveRecord::Base commit_status.run_after_commit do pipeline.try do |pipeline| + next if pipeline.are_update_events_suppressed? + if complete? PipelineProcessWorker.perform_async(pipeline.id) else - PipelineUpdateWorker.perform_async(pipeline.id) + PipelineUpdateWorker.perform_async(pipeline.id, commit_status.id, transition.from, transition.to) end end end diff --git a/app/services/ci/process_pipeline_service.rb b/app/services/ci/process_pipeline_service.rb index d3dd30b2588fb0af2fa338cef66af59823bd53a5..b6a741cff180b4269ae20e480b04fd8375124a86 100644 --- a/app/services/ci/process_pipeline_service.rb +++ b/app/services/ci/process_pipeline_service.rb @@ -10,16 +10,18 @@ def execute(pipeline) create_builds! end - @pipeline.with_lock do - new_builds = - stage_indexes_of_created_builds.map do |index| - process_stage(index) - end + @pipeline.suppress_update_events do + @pipeline.with_lock do + new_builds = + stage_indexes_of_created_builds.map do |index| + process_stage(index) + end - @pipeline.update_status + @pipeline.update_status - # Return a flag if a when builds got enqueued - new_builds.flatten.any? + # Return a flag if a when builds got enqueued + new_builds.flatten.any? + end end end