diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-08-31 16:32:05 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-09-07 14:58:55 +0300 |
commit | 6a29ac7d1d043474ec9352209243e0ea2118dc48 (patch) | |
tree | 350af71c69a25f29bc098eae608838aad0f8f21b /lib/ci/api | |
parent | 1d5488699678d22644d24add4b89cede0419ad25 (diff) |
Change update interval of runners when trying to preserve contacted_at
Diffstat (limited to 'lib/ci/api')
-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 |