summaryrefslogtreecommitdiff
path: root/lib/ci
diff options
context:
space:
mode:
authorJacob Vosmaer <contact@jacobvosmaer.nl>2015-11-02 16:02:47 +0100
committerJacob Vosmaer <contact@jacobvosmaer.nl>2015-11-02 16:02:47 +0100
commite032a7288f4103a6d5980da6af4040bc9271bd99 (patch)
treef11caf5e3a8913b0b01d5ef201bf0561151e4803 /lib/ci
parenta9f02300c885df3b7f7cad6d79e161b9547e8723 (diff)
downloadgitlab-ce-e032a7288f4103a6d5980da6af4040bc9271bd99.tar.gz
Spread out runner contacted_at updates
Diffstat (limited to 'lib/ci')
-rw-r--r--lib/ci/api/helpers.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/ci/api/helpers.rb b/lib/ci/api/helpers.rb
index e602cda81d6..7e4986b6af3 100644
--- a/lib/ci/api/helpers.rb
+++ b/lib/ci/api/helpers.rb
@@ -16,7 +16,9 @@ module Ci
end
def update_runner_last_contact
- if current_runner.contacted_at.nil? || Time.now - current_runner.contacted_at >= UPDATE_RUNNER_EVERY
+ # Use a random threshold to prevent beating DB updates
+ contacted_at_max_age = UPDATE_RUNNER_EVERY + Random.rand(UPDATE_RUNNER_EVERY)
+ if current_runner.contacted_at.nil? || Time.now - current_runner.contacted_at >= contacted_at_max_age
current_runner.update_attributes(contacted_at: Time.now)
end
end