diff options
author | Matija Čupić <matteeyah@gmail.com> | 2018-01-29 00:23:36 +0100 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2018-01-29 00:23:36 +0100 |
commit | b1c40590e7738a782d1295d743a6a3957723c4b3 (patch) | |
tree | dc735c0bb8d1f0b5b0ac45faf1c9ecc87be434cc | |
parent | dc325c672e20afa953117b0e1b04b2e399f391d7 (diff) | |
download | gitlab-ce-b1c40590e7738a782d1295d743a6a3957723c4b3.tar.gz |
Extend Runner API helpers with cache info storage
-rw-r--r-- | lib/api/helpers/runner.rb | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/api/helpers/runner.rb b/lib/api/helpers/runner.rb index 2cae53dba53..ad8c1c4407c 100644 --- a/lib/api/helpers/runner.rb +++ b/lib/api/helpers/runner.rb @@ -27,6 +27,8 @@ module API end def update_runner_info + update_runner_info_cache + return unless update_runner? current_runner.contacted_at = Time.now @@ -35,13 +37,17 @@ module API 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) + # Use a 1h threshold to prevent beating DB updates. current_runner.contacted_at.nil? || - (Time.now - current_runner.contacted_at) >= contacted_at_max_age + (Time.now - current_runner.contacted_at) >= UPDATE_RUNNER_EVERY + end + + def update_runner_info_cache + Gitlab::Redis::SharedState.with do |redis| + redis_key = "#{current_runner.runner_info_key}:contacted_at" + redis.set(redis_key, Time.now) + end end def validate_job!(job) |