Module: Ci::Metadatable

Extended by:
ActiveSupport::Concern
Includes:
Gitlab::Utils::StrongMemoize
Included in:
Processable
Defined in:
app/models/concerns/ci/metadatable.rb

Overview

This module implements methods that need to read and write metadata for CI/CD entities.

Instance Method Summary collapse

Instance Method Details

#artifacts_exposed_asObject



137
138
139
# File 'app/models/concerns/ci/metadatable.rb', line 137

def artifacts_exposed_as
  &.exposed_as || options.dig(:artifacts, :expose_as)
end

#artifacts_exposed_pathsObject



141
142
143
# File 'app/models/concerns/ci/metadatable.rb', line 141

def artifacts_exposed_paths
  &.exposed_paths || options.dig(:artifacts, :paths)
end

#debug_trace_enabled?Boolean

Returns:

  • (Boolean)


101
102
103
104
105
106
# File 'app/models/concerns/ci/metadatable.rb', line 101

def debug_trace_enabled?
  return debug_trace_enabled unless debug_trace_enabled.nil?
  return true if degenerated?

  !!&.debug_trace_enabled?
end

#degenerate!Object



68
69
70
71
72
73
74
75
76
# File 'app/models/concerns/ci/metadatable.rb', line 68

def degenerate!
  self.class.transaction do
    self.update!(options: nil, yaml_variables: nil)
    self.needs.all.delete_all
    self.&.destroy
    self.job_definition_instance&.destroy
    yield if block_given?
  end
end

#degenerated?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'app/models/concerns/ci/metadatable.rb', line 64

def degenerated?
  self.options.blank?
end

#downstream_errorsObject



145
146
147
# File 'app/models/concerns/ci/metadatable.rb', line 145

def downstream_errors
  error_job_messages.map(&:content).presence || options[:downstream_errors]
end

#enable_debug_trace!Object



108
109
110
# File 'app/models/concerns/ci/metadatable.rb', line 108

def enable_debug_trace!
  update!(debug_trace_enabled: true)
end

#exit_codeObject



154
155
156
# File 'app/models/concerns/ci/metadatable.rb', line 154

def exit_code
  read_attribute(:exit_code) || &.exit_code
end

#exit_code=(value) ⇒ Object



158
159
160
161
162
163
164
# File 'app/models/concerns/ci/metadatable.rb', line 158

def exit_code=(value)
  return unless value

  safe_value = value.to_i.clamp(0, Gitlab::Database::MAX_SMALLINT_VALUE)

  write_attribute(:exit_code, safe_value)
end

#has_exposed_artifacts?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'app/models/concerns/ci/metadatable.rb', line 60

def has_exposed_artifacts?
  artifacts_exposed_as.present?
end

#id_tokensObject



93
94
95
# File 'app/models/concerns/ci/metadatable.rb', line 93

def id_tokens
  (nil, :id_tokens, :id_tokens, {}).deep_stringify_keys
end

#id_tokens=(_value) ⇒ Object

Raises:

  • (ActiveRecord::ReadonlyAttributeError)


186
187
188
# File 'app/models/concerns/ci/metadatable.rb', line 186

def id_tokens=(_value)
  raise ActiveRecord::ReadonlyAttributeError, 'This data is read only'
end

#id_tokens?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'app/models/concerns/ci/metadatable.rb', line 97

def id_tokens?
  id_tokens.present?
end

#interruptibleObject



86
87
88
89
90
91
# File 'app/models/concerns/ci/metadatable.rb', line 86

def interruptible
  return job_definition.interruptible if job_definition
  return temp_job_definition.interruptible if temp_job_definition

  &.read_attribute(:interruptible)
end

#interruptible=(_value) ⇒ Object

Raises:

  • (ActiveRecord::ReadonlyAttributeError)


182
183
184
# File 'app/models/concerns/ci/metadatable.rb', line 182

def interruptible=(_value)
  raise ActiveRecord::ReadonlyAttributeError, 'This data is read only'
end

#optionsObject



78
79
80
# File 'app/models/concerns/ci/metadatable.rb', line 78

def options
  (:options, :config_options, :options, {})
end

#options=(value) ⇒ Object

Should be removed when the column is dropped from p_ci_builds allows deleting data for degenerate!

Raises:

  • (ActiveRecord::ReadonlyAttributeError)


168
169
170
171
172
# File 'app/models/concerns/ci/metadatable.rb', line 168

def options=(value)
  raise ActiveRecord::ReadonlyAttributeError, 'This data is read only' unless value.nil?

  super
end

#scoped_user_idObject



150
151
152
# File 'app/models/concerns/ci/metadatable.rb', line 150

def scoped_user_id
  read_attribute(:scoped_user_id) || options[:scoped_user_id]
end

#secrets=(_value) ⇒ Object

Raises:

  • (ActiveRecord::ReadonlyAttributeError)


190
191
192
# File 'app/models/concerns/ci/metadatable.rb', line 190

def secrets=(_value)
  raise ActiveRecord::ReadonlyAttributeError, 'This data is read only'
end

#timeout_human_readable_valueObject



112
113
114
# File 'app/models/concerns/ci/metadatable.rb', line 112

def timeout_human_readable_value
  timeout_human_readable || &.timeout_human_readable
end

#timeout_source_valueObject

metadata has unknown_timeout_source as default



133
134
135
# File 'app/models/concerns/ci/metadatable.rb', line 133

def timeout_source_value
  timeout_source || &.timeout_source || 'unknown_timeout_source'
end

#timeout_valueObject



116
117
118
# File 'app/models/concerns/ci/metadatable.rb', line 116

def timeout_value
  timeout || &.timeout
end

#update_timeout_stateObject

This method is called from within a Ci::Build state transition; it returns nil/true (success) or false (failure)



122
123
124
125
126
127
128
129
130
# File 'app/models/concerns/ci/metadatable.rb', line 122

def update_timeout_state
  timeout = ::Ci::Builds::TimeoutCalculator.new(self).applicable_timeout
  return unless timeout

  # We don't use update because we're already in a Ci::Build transaction
  write_attribute(:timeout, timeout.value)
  write_attribute(:timeout_source, timeout.source)
  valid?
end

#yaml_variablesObject



82
83
84
# File 'app/models/concerns/ci/metadatable.rb', line 82

def yaml_variables
  (:yaml_variables, :config_variables, :yaml_variables, [])
end

#yaml_variables=(value) ⇒ Object

Should be removed when the column is dropped from p_ci_builds allows deleting data for degenerate!

Raises:

  • (ActiveRecord::ReadonlyAttributeError)


176
177
178
179
180
# File 'app/models/concerns/ci/metadatable.rb', line 176

def yaml_variables=(value)
  raise ActiveRecord::ReadonlyAttributeError, 'This data is read only' unless value.nil?

  super
end