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

Move redis-logic into Ci::Runner

parent 771dd68c
......@@ -21,6 +21,8 @@ module Ci
scope :online, ->() { where('contacted_at > ?', LAST_CONTACT_TIME) }
scope :ordered, ->() { order(id: :desc) }
after_save :tick_update
scope :owned_or_shared, ->(project_id) do
joins('LEFT JOIN ci_runner_projects ON ci_runner_projects.runner_id = ci_runners.id')
.where("ci_runner_projects.gl_project_id = :project_id OR ci_runners.is_shared = true", project_id: project_id)
......@@ -122,8 +124,22 @@ module Ci
]
end
def tick_update
new_update = Time.new.inspect
Gitlab::Redis.with { |redis| redis.set(redis_key, new_update, ex: 60.minutes) }
new_update
end
def last_build_queue_update
Gitlab::Redis.with { |redis| redis.get(redis_key) }
end
private
def redis_key
"runner:build_queue:#{self.id}"
end
def tag_constraints
unless has_tags? || run_untagged?
errors.add(:tags_list,
......
......@@ -16,7 +16,7 @@ module Ci
not_found! unless current_runner.active?
update_runner_info
last_update = Gitlab::Redis.with { |redis| redis.get(current_runner_redis_key)}
last_update = current_runner.last_build_queue_update
if params[:last_update].present?
if params[:last_update] == last_update
......@@ -35,13 +35,8 @@ module Ci
else
Gitlab::Metrics.add_event(:build_not_found)
if last_update == ""
Gitlab::Redis.with do |redis|
new_update = Time.new.inspect
redis.set(current_runner_redis_key, new_update, ex: 60.minutes)
new_update = current_runner.tick_update
headers 'X-GitLab-Last-Update', new_update
end
end
build_not_found!
end
......
......@@ -60,10 +60,6 @@ module Ci
@runner ||= Runner.find_by_token(params[:token].to_s)
end
def current_runner_redis_key
@runner_redis_key ||= "#{current_runner.token}_#{current_runner.tag_list}"
end
def get_runner_version_from_params
return unless params["info"].present?
attributes_for_keys(["name", "version", "revision", "platform", "architecture"], params["info"])
......
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