summaryrefslogtreecommitdiff
path: root/lib/ci/api/builds.rb
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2017-03-21 13:58:31 +0100
committerKamil Trzcinski <ayufan@ayufan.eu>2017-03-21 13:58:31 +0100
commit830198b75c1fc75791187455f7976f0a87493ef7 (patch)
treef4fb575b8c553ba427f648371382016d266b32a0 /lib/ci/api/builds.rb
parent46146e33f2f8dcbd52ee50eb9142887344b8c367 (diff)
downloadgitlab-ce-improve-ci-redis-queueing.tar.gz
Improve resiliency of build pickingimprove-ci-redis-queueing
Every time we pick a new build, or we get into conflict we force runner to retry the operation to make sure that all builds are being picked. It makes us to loose one request, but also makes sure that we are consistent. It is fair trade, as number of generated builds is relatively small 0.1% compared to the traffic.
Diffstat (limited to 'lib/ci/api/builds.rb')
-rw-r--r--lib/ci/api/builds.rb29
1 files changed, 19 insertions, 10 deletions
diff --git a/lib/ci/api/builds.rb b/lib/ci/api/builds.rb
index 746e76a1b1f..f39b509873c 100644
--- a/lib/ci/api/builds.rb
+++ b/lib/ci/api/builds.rb
@@ -13,35 +13,44 @@ module Ci
post "register" do
authenticate_runner!
required_attributes! [:token]
- not_found! unless current_runner.active?
update_runner_info
if current_runner.is_runner_queue_value_latest?(params[:last_update])
- header 'X-GitLab-Last-Update', params[:last_update]
- Gitlab::Metrics.add_event(:build_not_found_cached)
+ Gitlab::Metrics.add_event(:build_not_found_cached,
+ version: get_runner_version)
+ header_last_update(params[:last_update])
return build_not_found!
end
new_update = current_runner.ensure_runner_queue_value
+ unless current_runner.active?
+ Gitlab::Metrics.add_event(:runner_inactive,
+ version: get_runner_version)
+ header_last_update(new_update)
+ return build_not_found!
+ end
+
result = Ci::RegisterJobService.new(current_runner).execute
if result.valid?
if result.build
Gitlab::Metrics.add_event(:build_found,
- project: result.build.project.path_with_namespace)
-
+ project: result.build.project.path_with_namespace,
+ version: get_runner_version)
+ header_last_update(current_runner.tick_runner_queue_value)
present result.build, with: Entities::BuildDetails
else
- Gitlab::Metrics.add_event(:build_not_found)
-
- header 'X-GitLab-Last-Update', new_update
-
+ Gitlab::Metrics.add_event(:build_not_found,
+ version: get_runner_version)
+ header_last_update(new_update)
build_not_found!
end
else
# We received build that is invalid due to concurrency conflict
- Gitlab::Metrics.add_event(:build_invalid)
+ Gitlab::Metrics.add_event(:build_invalid,
+ version: get_runner_version)
+ header_last_update(current_runner.tick_runner_queue_value)
conflict!
end
end