diff options
author | Matija Čupić <matteeyah@gmail.com> | 2018-01-29 20:56:28 +0100 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2018-01-29 20:56:28 +0100 |
commit | bdd3e39b0bd4e8fcec5d6e2d97297840211dd921 (patch) | |
tree | 80b344923c69a2096383d8f39e33ddaf9657421b /lib/api/helpers/runner.rb | |
parent | 92ac2b9ee68cad8c01a199e6475bbef272818da5 (diff) | |
download | gitlab-ce-bdd3e39b0bd4e8fcec5d6e2d97297840211dd921.tar.gz |
Move info update implementation to Ci::Runner model
Diffstat (limited to 'lib/api/helpers/runner.rb')
-rw-r--r-- | lib/api/helpers/runner.rb | 27 |
1 files changed, 1 insertions, 26 deletions
diff --git a/lib/api/helpers/runner.rb b/lib/api/helpers/runner.rb index 5ac9181f878..8f45cae0e60 100644 --- a/lib/api/helpers/runner.rb +++ b/lib/api/helpers/runner.rb @@ -5,7 +5,6 @@ module API JOB_TOKEN_HEADER = 'HTTP_JOB_TOKEN'.freeze JOB_TOKEN_PARAM = :token - UPDATE_RUNNER_EVERY = 10 * 60 def runner_registration_token_valid? ActiveSupport::SecurityUtils.variable_size_secure_compare(params[:token], @@ -21,37 +20,13 @@ module API def authenticate_runner! forbidden! unless current_runner - update_runner_info + current_runner.update_runner_info(get_runner_version_from_params) end def current_runner @runner ||= ::Ci::Runner.find_by_token(params[:token].to_s) end - def update_runner_info - update_runner_info_cache - - return unless update_runner? - - current_runner.contacted_at = Time.now - current_runner.assign_attributes(get_runner_version_from_params) - current_runner.save if current_runner.changed? - end - - def update_runner? - # Use a 1h threshold to prevent beating DB updates. - - current_runner.contacted_at.nil? || - (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) not_found! unless job |