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,19 +23,25 @@ module Ci ...@@ -23,19 +23,25 @@ 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 build if valid
Gitlab::Metrics.add_event(:build_found, if build
project: build.project.path_with_namespace) Gitlab::Metrics.add_event(:build_found,
project: build.project.path_with_namespace)
present build, with: Entities::BuildDetails present build, with: Entities::BuildDetails
else else
Gitlab::Metrics.add_event(:build_not_found) Gitlab::Metrics.add_event(:build_not_found)
header 'X-GitLab-Last-Update', new_update header 'X-GitLab-Last-Update', new_update
build_not_found! build_not_found!
end
else
# We received build that is invalid due to concurrency conflict
Gitlab::Metrics.add_event(:build_invalid)
conflict!
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