summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-10-19 12:32:55 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2016-10-19 12:33:35 +0200
commitf68a63b5dd4a8ccc1be7c4cb3968d7c49581cce4 (patch)
tree40704f55ade78a0e065528cd1e5114ec856bb664
parent72af0e73833f06cfcd10126bc03c688358260e60 (diff)
downloadgitlab-ce-suppress-update-events-on-pipeline.tar.gz
Suppress update events on pipeline if already they got scheduledsuppress-update-events-on-pipeline
-rw-r--r--app/models/ci/pipeline.rb20
-rw-r--r--app/models/commit_status.rb4
-rw-r--r--app/services/ci/process_pipeline_service.rb18
3 files changed, 32 insertions, 10 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index e75fe6c222b..aa493ef6fad 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -104,6 +104,22 @@ module Ci
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 @@ module Ci
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 7b554be4f9a..b9e3d6bee53 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 d3dd30b2588..b6a741cff18 100644
--- a/app/services/ci/process_pipeline_service.rb
+++ b/app/services/ci/process_pipeline_service.rb
@@ -10,16 +10,18 @@ module Ci
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