diff options
author | Robert Speicher <robert@gitlab.com> | 2015-11-03 16:14:42 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2015-11-03 16:14:42 +0000 |
commit | cc40c7af4da01963b4939591cd8c5aa3ba617ba0 (patch) | |
tree | 10e61f781db9c5d9df46f1ed1c3c7c1bdc5e8d6b /lib | |
parent | a74aba01b21b069906de1fb01347da9b3f5d2948 (diff) | |
parent | 2674a14becba89bb6b5259cd0ff3e5b29b724325 (diff) | |
download | gitlab-ce-cc40c7af4da01963b4939591cd8c5aa3ba617ba0.tar.gz |
Merge branch 'spread-runner-last-updated-at' into 'master'
Spread out runner contacted_at updates
This is meant to prevent having too many concurrent UPDATE requests
caused by runners checking in.
See merge request !1722
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ci/api/helpers.rb | 4 |
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 |