diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-09-08 13:08:50 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-09-08 13:08:50 +0300 |
commit | 575a97470e1855734a337b4bb13bcd5bf1b34efe (patch) | |
tree | ae252617b333edb7624bcd6cd6ea27ea943f4156 /lib/ci | |
parent | 6343a3c49d647f14983aa2a53cb15b23181b8f61 (diff) | |
parent | 6a29ac7d1d043474ec9352209243e0ea2118dc48 (diff) |
Merge branch 'change-update-interval-of-runners' into 'master'
Change update interval of runners when trying to preserve contacted_at
See merge request !6126
Diffstat (limited to 'lib/ci')
-rw-r--r-- | lib/ci/api/builds.rb | 2 | ||||
-rw-r--r-- | lib/ci/api/helpers.rb | 8 |
2 files changed, 6 insertions, 4 deletions
diff --git a/lib/ci/api/builds.rb b/lib/ci/api/builds.rb index 9f3b582a263..eb4947cdbf1 100644 --- a/lib/ci/api/builds.rb +++ b/lib/ci/api/builds.rb @@ -12,7 +12,7 @@ module Ci # POST /builds/register post "register" do authenticate_runner! - update_runner_last_contact + update_runner_last_contact(save: false) update_runner_info required_attributes! [:token] not_found! unless current_runner.active? diff --git a/lib/ci/api/helpers.rb b/lib/ci/api/helpers.rb index 199d62d9b8a..bcabf7a21b2 100644 --- a/lib/ci/api/helpers.rb +++ b/lib/ci/api/helpers.rb @@ -3,7 +3,7 @@ module Ci module Helpers BUILD_TOKEN_HEADER = "HTTP_BUILD_TOKEN" BUILD_TOKEN_PARAM = :token - UPDATE_RUNNER_EVERY = 60 + UPDATE_RUNNER_EVERY = 40 * 60 def authenticate_runners! forbidden! unless runner_registration_token_valid? @@ -22,11 +22,13 @@ module Ci params[:token] == current_application_settings.runners_registration_token end - def update_runner_last_contact + def update_runner_last_contact(save: true) # 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) if current_runner.contacted_at.nil? || Time.now - current_runner.contacted_at >= contacted_at_max_age - current_runner.update_attributes(contacted_at: Time.now) + current_runner.contacted_at = Time.now + current_runner.save if current_runner.changed? && save end end |