diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-12-06 17:30:20 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-12-06 17:30:20 +0300 |
commit | 5ccced63122fe2d21fff7d7298db1081776193b4 (patch) | |
tree | 2230f209888e118abac7dbe13f073e0bb5195576 /lib/gitlab/ci | |
parent | 382a1ef45360b538a80fd5d34cde71f53522dc2a (diff) |
Move invalid builds counter out of the transaction
Diffstat (limited to 'lib/gitlab/ci')
-rw-r--r-- | lib/gitlab/ci/pipeline/chain/create.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/ci/stage/seed.rb | 13 |
2 files changed, 17 insertions, 13 deletions
diff --git a/lib/gitlab/ci/pipeline/chain/create.rb b/lib/gitlab/ci/pipeline/chain/create.rb index d5e17a123df..42ae1650437 100644 --- a/lib/gitlab/ci/pipeline/chain/create.rb +++ b/lib/gitlab/ci/pipeline/chain/create.rb @@ -17,11 +17,28 @@ module Gitlab end rescue ActiveRecord::RecordInvalid => 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 def break? !pipeline.persisted? 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 diff --git a/lib/gitlab/ci/stage/seed.rb b/lib/gitlab/ci/stage/seed.rb index 6a3b2f6cc4a..bc97aa63b02 100644 --- a/lib/gitlab/ci/stage/seed.rb +++ b/lib/gitlab/ci/stage/seed.rb @@ -39,10 +39,6 @@ module Gitlab pipeline.stages.create!(stage).tap do |stage| builds_attributes = builds.map do |attributes| attributes.merge(stage_id: stage.id) - - if attributes.fetch(:stage_id).nil? - invalid_builds_counter.increment(node: hostname) - end end pipeline.builds.create!(builds_attributes).each do |build| @@ -56,15 +52,6 @@ module Gitlab def protected_ref? @protected_ref ||= project.protected_for?(pipeline.ref) 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 |