Extract method that checks if ci runner needs update
This commit is contained in:
parent
08e31875c2
commit
9a8e486307
1 changed files with 11 additions and 4 deletions
|
@ -31,16 +31,23 @@ module Ci
|
|||
end
|
||||
|
||||
def update_runner_info
|
||||
# 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)
|
||||
return unless current_runner.contacted_at.nil? || Time.now - current_runner.contacted_at >= contacted_at_max_age
|
||||
return unless update_runner?
|
||||
|
||||
current_runner.contacted_at = Time.now
|
||||
current_runner.assign_attributes(get_runner_version_from_params)
|
||||
current_runner.save if current_runner.changed?
|
||||
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!
|
||||
if headers['User-Agent'].match(/gitlab-ci-multi-runner \d+\.\d+\.\d+(~beta\.\d+\.g[0-9a-f]+)? /)
|
||||
no_content!
|
||||
|
|
Loading…
Reference in a new issue