Class: Ci::RunnerManager

Inherits:
ApplicationRecord show all
Includes:
HasRunnerExecutor, FromUnion, RedisCacheable
Defined in:
app/models/ci/runner_manager.rb

Constant Summary collapse

UPDATE_CONTACT_COLUMN_EVERY =

The ‘UPDATE_CONTACT_COLUMN_EVERY` defines how often the Runner Machine DB entry can be updated

(40.minutes)..(55.minutes)
STALE_TIMEOUT =

The ‘STALE_TIMEOUT` constant defines the how far past the last contact or creation date a runner manager will be considered stale

7.days

Constants included from RedisCacheable

RedisCacheable::CACHED_ATTRIBUTES_EXPIRY_TIME

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RedisCacheable

#cache_attributes, #cached_attribute, #merge_cache_attributes

Methods inherited from ApplicationRecord

model_name, table_name_prefix

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.aggregate_upgrade_status_by_runner_idObject



77
78
79
80
81
82
# File 'app/models/ci/runner_manager.rb', line 77

def self.aggregate_upgrade_status_by_runner_id
  joins(:runner_version)
    .group(:runner_id)
    .maximum(:status)
    .transform_values { |s| Ci::RunnerVersion.statuses.key(s).to_sym }
end

.online_contact_time_deadlineObject



69
70
71
# File 'app/models/ci/runner_manager.rb', line 69

def self.online_contact_time_deadline
  Ci::Runner.online_contact_time_deadline
end

.stale_deadlineObject



73
74
75
# File 'app/models/ci/runner_manager.rb', line 73

def self.stale_deadline
  STALE_TIMEOUT.ago
end

Instance Method Details

#heartbeat(values, update_contacted_at: true) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/models/ci/runner_manager.rb', line 84

def heartbeat(values, update_contacted_at: true)
  ##
  # We can safely ignore writes performed by a runner heartbeat. We do
  # not want to upgrade database connection proxy to use the primary
  # database after heartbeat write happens.
  #
  ::Gitlab::Database::LoadBalancing::Session.without_sticky_writes do
    values = values&.slice(:version, :revision, :platform, :architecture, :ip_address, :config, :executor) || {}
    values[:contacted_at] = Time.current if update_contacted_at
    if values.include?(:executor)
      values[:executor_type] = Ci::Runner::EXECUTOR_NAME_TO_TYPES.fetch(values.delete(:executor), :unknown)
    end

    new_version = values[:version]
    schedule_runner_version_update(new_version) if new_version && new_version != version

    merge_cache_attributes(values)

    # We save data without validation, it will always change due to `contacted_at`
    update_columns(values) if persist_cached_data?
  end
end

#statusObject



107
108
109
110
111
112
# File 'app/models/ci/runner_manager.rb', line 107

def status
  return :stale if stale?
  return :never_contacted unless contacted_at

  online? ? :online : :offline
end