Коммит f68a63b5 создал по автору Kamil Trzcinski's avatar Kamil Trzcinski
Просмотр файлов

Suppress update events on pipeline if already they got scheduled

владелец 72af0e73
......@@ -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?
......
......@@ -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
......
......@@ -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
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать