summaryrefslogtreecommitdiff
path: root/lib/ci/api
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-10-03 10:47:37 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-10-03 12:07:47 +0200
commit9a8e486307550aa1a590c769d9e71621c5ce8c62 (patch)
treee2bafc759155a32159578bdd51623c0fff5d0dc7 /lib/ci/api
parent08e31875c2d345c0755707ab73c1fd71b1fd9b05 (diff)
downloadgitlab-ce-9a8e486307550aa1a590c769d9e71621c5ce8c62.tar.gz
Extract method that checks if ci runner needs update
Diffstat (limited to 'lib/ci/api')
-rw-r--r--lib/ci/api/helpers.rb15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/ci/api/helpers.rb b/lib/ci/api/helpers.rb
index c6a83682e32..e608f5f6cad 100644
--- a/lib/ci/api/helpers.rb
+++ b/lib/ci/api/helpers.rb
@@ -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!