Commit 3441b4f9 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Fix picking CI builds

The conflict happens when we try to update a build,
but fail to do so due to fact that we update the same build concurrently for two different runners.
parent b368447c
...@@ -29,10 +29,10 @@ module Ci ...@@ -29,10 +29,10 @@ module Ci
build.run! build.run!
end end
build [build, true]
rescue StateMachines::InvalidTransition, ActiveRecord::StaleObjectError rescue StateMachines::InvalidTransition, ActiveRecord::StaleObjectError
nil [nil, false]
end end
private private
......
...@@ -23,8 +23,9 @@ module Ci ...@@ -23,8 +23,9 @@ module Ci
new_update = current_runner.ensure_runner_queue_value new_update = current_runner.ensure_runner_queue_value
build = Ci::RegisterBuildService.new(current_runner).execute build, valid = Ci::RegisterBuildService.new(current_runner).execute
if valid
if build if build
Gitlab::Metrics.add_event(:build_found, Gitlab::Metrics.add_event(:build_found,
project: build.project.path_with_namespace) project: build.project.path_with_namespace)
...@@ -37,6 +38,11 @@ module Ci ...@@ -37,6 +38,11 @@ module Ci
build_not_found! build_not_found!
end end
else
# We received build that is invalid due to concurrency conflict
Gitlab::Metrics.add_event(:build_invalid)
conflict!
end
end end
# Update an existing build - Runners only # Update an existing build - Runners only
......
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