diff options
Diffstat (limited to 'lib/api/ci/helpers/runner.rb')
-rw-r--r-- | lib/api/ci/helpers/runner.rb | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/api/ci/helpers/runner.rb b/lib/api/ci/helpers/runner.rb index be4d82bc500..96f5265ce23 100644 --- a/lib/api/ci/helpers/runner.rb +++ b/lib/api/ci/helpers/runner.rb @@ -10,23 +10,32 @@ module API JOB_TOKEN_HEADER = 'HTTP_JOB_TOKEN' JOB_TOKEN_PARAM = :token + LEGACY_SYSTEM_XID = '<legacy>' def authenticate_runner! track_runner_authentication forbidden! unless current_runner - current_runner - .heartbeat(get_runner_details_from_request) + runner_details = get_runner_details_from_request + current_runner.heartbeat(runner_details) + current_runner_machine&.heartbeat(runner_details) end def get_runner_details_from_request return get_runner_ip unless params['info'].present? attributes_for_keys(%w(name version revision platform architecture executor), params['info']) + .merge(get_system_id_from_request) .merge(get_runner_config_from_request) .merge(get_runner_ip) end + def get_system_id_from_request + return { system_id: params[:system_id] } if params.include?(:system_id) + + {} + end + def get_runner_ip { ip_address: ip_address } end @@ -43,6 +52,15 @@ module API end end + def current_runner_machine + return if Feature.disabled?(:create_runner_machine) + + strong_memoize(:current_runner_machine) do + system_xid = params.fetch(:system_id, LEGACY_SYSTEM_XID) + current_runner&.ensure_machine(system_xid) { |m| m.contacted_at = Time.current } + end + end + def track_runner_authentication if current_runner metrics.increment_runner_authentication_success_counter(runner_type: current_runner.runner_type) @@ -78,6 +96,7 @@ module API # the heartbeat should be triggered. if heartbeat_runner job.runner&.heartbeat(get_runner_ip) + job.runner_machine&.heartbeat(get_runner_ip) end job |