Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib/ci
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-10-03 11:47:37 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-10-03 13:07:47 +0300
commit9a8e486307550aa1a590c769d9e71621c5ce8c62 (patch)
treee2bafc759155a32159578bdd51623c0fff5d0dc7 /lib/ci
parent08e31875c2d345c0755707ab73c1fd71b1fd9b05 (diff)
Extract method that checks if ci runner needs update
Diffstat (limited to 'lib/ci')
-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!