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

#NamingThings

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