Commit 4fe5bdfe authored by Matija Čupić's avatar Matija Čupić

Extend Runner API helpers with cache info storage

parent 8f4b6e2e
...@@ -27,6 +27,8 @@ module API ...@@ -27,6 +27,8 @@ module API
end end
def update_runner_info def update_runner_info
update_runner_info_cache
return unless update_runner? return unless update_runner?
current_runner.contacted_at = Time.now current_runner.contacted_at = Time.now
...@@ -35,13 +37,17 @@ module API ...@@ -35,13 +37,17 @@ module API
end end
def update_runner? def update_runner?
# Use a random threshold to prevent beating DB updates. # Use a 1h 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)
current_runner.contacted_at.nil? || 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 end
def validate_job!(job) def validate_job!(job)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment