Class: Ci::RunnerManager
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ApplicationRecord
- Ci::RunnerManager
- Includes:
- HasRunnerExecutor, HasRunnerStatus, EachBatch, FromUnion, RedisCacheable
- Defined in:
- app/models/ci/runner_manager.rb
Constant Summary collapse
- AVAILABLE_STATUSES =
%w[online offline never_contacted stale].freeze
- AVAILABLE_STATUSES_INCL_DEPRECATED =
AVAILABLE_STATUSES
- UPDATE_CONTACT_COLUMN_EVERY =
The ‘UPDATE_CONTACT_COLUMN_EVERY` defines how often the Runner Machine DB entry can be updated
(40.minutes)..(55.minutes)
- EXECUTOR_NAME_TO_TYPES =
{ 'unknown' => :unknown, 'custom' => :custom, 'shell' => :shell, 'docker' => :docker, 'docker-windows' => :docker_windows, 'docker-ssh' => :docker_ssh, 'ssh' => :ssh, 'parallels' => :parallels, 'virtualbox' => :virtualbox, 'docker+machine' => :docker_machine, 'docker-ssh+machine' => :docker_ssh_machine, 'kubernetes' => :kubernetes, 'docker-autoscaler' => :docker_autoscaler, 'instance' => :instance }.freeze
- EXECUTOR_TYPE_TO_NAMES =
EXECUTOR_NAME_TO_TYPES.invert.freeze
- 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
Constants included from HasCheckConstraints
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
Constants included from ResetOnColumnErrors
ResetOnColumnErrors::MAX_RESET_PERIOD
Class Method Summary collapse
- .aggregate_upgrade_status_by_runner_id ⇒ Object
- .online_contact_time_deadline ⇒ Object
- .stale_deadline ⇒ Object
Instance Method Summary collapse
Methods included from HasRunnerStatus
Methods included from RedisCacheable
#cache_attributes, #cached_attribute, #merge_cache_attributes
Methods inherited from ApplicationRecord
Methods inherited from ApplicationRecord
===, cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, nullable_column?, 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 ResetOnColumnErrors
#reset_on_union_error, #reset_on_unknown_attribute_error
Methods included from Gitlab::SensitiveSerializableHash
Class Method Details
.aggregate_upgrade_status_by_runner_id ⇒ Object
132 133 134 135 136 137 |
# File 'app/models/ci/runner_manager.rb', line 132 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_deadline ⇒ Object
124 125 126 |
# File 'app/models/ci/runner_manager.rb', line 124 def self.online_contact_time_deadline Ci::Runner.online_contact_time_deadline end |
.stale_deadline ⇒ Object
128 129 130 |
# File 'app/models/ci/runner_manager.rb', line 128 def self.stale_deadline STALE_TIMEOUT.ago end |
Instance Method Details
#heartbeat(values, update_contacted_at: true) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'app/models/ci/runner_manager.rb', line 143 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::SessionMap.current(load_balancer).without_sticky_writes do values = values&.slice(:version, :revision, :platform, :architecture, :ip_address, :config, :executor) || {} values.merge!(contacted_at: Time.current, creation_state: :finished) if update_contacted_at if values.include?(:executor) values[:executor_type] = 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 |
#uncached_contacted_at ⇒ Object
139 140 141 |
# File 'app/models/ci/runner_manager.rb', line 139 def uncached_contacted_at read_attribute(:contacted_at) end |