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
build.run!
end
build
[build, true]
rescue StateMachines::InvalidTransition, ActiveRecord::StaleObjectError
nil
[nil, false]
end
private
......
......@@ -23,19 +23,25 @@ module Ci
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
Gitlab::Metrics.add_event(:build_found,
project: build.project.path_with_namespace)
if valid
if build
Gitlab::Metrics.add_event(:build_found,
project: build.project.path_with_namespace)
present build, with: Entities::BuildDetails
else
Gitlab::Metrics.add_event(:build_not_found)
present build, with: Entities::BuildDetails
else
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
......
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