Commit 9a8e4863 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Extract method that checks if ci runner needs update

parent 08e31875
...@@ -31,16 +31,23 @@ module Ci ...@@ -31,16 +31,23 @@ module Ci
end end
def update_runner_info def update_runner_info
# Use a random threshold to prevent beating DB updates return unless update_runner?
# it generates a distribution between: [40m, 80m]
contacted_at_max_age = UPDATE_RUNNER_EVERY + Random.rand(UPDATE_RUNNER_EVERY)
return unless current_runner.contacted_at.nil? || Time.now - current_runner.contacted_at >= contacted_at_max_age
current_runner.contacted_at = Time.now current_runner.contacted_at = Time.now
current_runner.assign_attributes(get_runner_version_from_params) current_runner.assign_attributes(get_runner_version_from_params)
current_runner.save if current_runner.changed? current_runner.save if current_runner.changed?
end end
def update_runner?
# Use a random threshold to prevent beating DB updates.
# It generates a distribution between [40m, 80m].
#
contacted_at_max_age = UPDATE_RUNNER_EVERY + Random.rand(UPDATE_RUNNER_EVERY)
current_runner.contacted_at.nil? ||
(Time.now - current_runner.contacted_at) >= contacted_at_max_age
end
def build_not_found! def build_not_found!
if headers['User-Agent'].match(/gitlab-ci-multi-runner \d+\.\d+\.\d+(~beta\.\d+\.g[0-9a-f]+)? /) if headers['User-Agent'].match(/gitlab-ci-multi-runner \d+\.\d+\.\d+(~beta\.\d+\.g[0-9a-f]+)? /)
no_content! no_content!
......
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