Commit 5ccced63 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Move invalid builds counter out of the transaction

parent 382a1ef4
...@@ -17,11 +17,28 @@ module Gitlab ...@@ -17,11 +17,28 @@ module Gitlab
end end
rescue ActiveRecord::RecordInvalid => e rescue ActiveRecord::RecordInvalid => e
error("Failed to persist the pipeline: #{e}") error("Failed to persist the pipeline: #{e}")
ensure
pipeline.builds.find_each do |build|
next if build.stage_id.present?
invalid_builds_counter.increment(node: hostname)
end
end end
def break? def break?
!pipeline.persisted? !pipeline.persisted?
end end
private
def invalid_builds_counter
@counter ||= Gitlab::Metrics
.counter(:invalid_builds_counter, 'Invalid builds counter')
end
def hostname
@hostname ||= Socket.gethostname
end
end end
end end
end end
......
...@@ -39,10 +39,6 @@ module Gitlab ...@@ -39,10 +39,6 @@ module Gitlab
pipeline.stages.create!(stage).tap do |stage| pipeline.stages.create!(stage).tap do |stage|
builds_attributes = builds.map do |attributes| builds_attributes = builds.map do |attributes|
attributes.merge(stage_id: stage.id) attributes.merge(stage_id: stage.id)
if attributes.fetch(:stage_id).nil?
invalid_builds_counter.increment(node: hostname)
end
end end
pipeline.builds.create!(builds_attributes).each do |build| pipeline.builds.create!(builds_attributes).each do |build|
...@@ -56,15 +52,6 @@ module Gitlab ...@@ -56,15 +52,6 @@ module Gitlab
def protected_ref? def protected_ref?
@protected_ref ||= project.protected_for?(pipeline.ref) @protected_ref ||= project.protected_for?(pipeline.ref)
end end
def invalid_builds_counter
@counter ||= Gitlab::Metrics.counter(:invalid_builds_counter,
'Builds without stage assigned counter')
end
def hostname
@hostname ||= Socket.gethostname
end
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