Commit 811addf2 authored by Kim "BKC" Carlbäcker's avatar Kim "BKC" Carlbäcker

#NamingThings

parent a20681c0
...@@ -124,19 +124,30 @@ module Ci ...@@ -124,19 +124,30 @@ module Ci
] ]
end end
def tick_update def tick_runner_queue
new_update = Time.new.inspect new_update = Time.new.inspect
Gitlab::Redis.with { |redis| redis.set(redis_key, new_update, ex: 60.minutes) } Gitlab::Redis.with { |redis| redis.set(runner_queue_key, new_update, ex: 60.minutes) }
new_update new_update
end end
def last_build_queue_update def ensure_runner_queue_value
Gitlab::Redis.with { |redis| redis.get(redis_key) } Gitlab::Redis.with do |redis|
value = redis.get(runner_queue_key)
if value == ""
value = Time.new.inspect
redis.set(runner_queue_key, value, ex: 60.minutes)
end
value
end
end
def is_runner_queue_value_latest?(value)
ensure_runner_queue_value == value if value.present?
end end
private private
def redis_key def runner_queue_key
"runner:build_queue:#{self.id}" "runner:build_queue:#{self.id}"
end end
......
module Ci module Ci
class UpdateBuildQueueService < BaseService class UpdateBuildQueueService < BaseService
def execute(build) def execute(build)
build.project.runners.select do |runner| build.project.runners.select do |runner|
if runner.can_pick?(build) if runner.can_pick?(build)
......
...@@ -4,8 +4,7 @@ class BuildQueueWorker ...@@ -4,8 +4,7 @@ class BuildQueueWorker
def perform(build_id) def perform(build_id)
Ci::Build.find_by(id: build_id).try do |build| Ci::Build.find_by(id: build_id).try do |build|
UpdateBuildQueueService.new(build) UpdateBuildQueueService.execute(build)
end end
end end
end end
...@@ -16,13 +16,9 @@ module Ci ...@@ -16,13 +16,9 @@ module Ci
not_found! unless current_runner.active? not_found! unless current_runner.active?
update_runner_info update_runner_info
last_update = current_runner.last_build_queue_update if current_runner.is_runner_queue_value_latest?(params[:last_update])
headers 'X-GitLab-Last-Update', params[:last_update]
if params[:last_update].present? return build_not_found!
if params[:last_update] == last_update
headers 'X-GitLab-Last-Update', last_update
return build_not_found!
end
end end
build = Ci::RegisterBuildService.new.execute(current_runner) build = Ci::RegisterBuildService.new.execute(current_runner)
...@@ -35,7 +31,7 @@ module Ci ...@@ -35,7 +31,7 @@ module Ci
else else
Gitlab::Metrics.add_event(:build_not_found) Gitlab::Metrics.add_event(:build_not_found)
new_update = current_runner.tick_update new_update = current_runner.ensure_runner_queue_value
headers 'X-GitLab-Last-Update', new_update headers 'X-GitLab-Last-Update', new_update
build_not_found! build_not_found!
......
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