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
- #artifacts_exposed_as ⇒ Object
- #artifacts_exposed_paths ⇒ Object
- #debug_trace_enabled? ⇒ Boolean
- #degenerate! ⇒ Object
- #degenerated? ⇒ Boolean
- #downstream_errors ⇒ Object
- #enable_debug_trace! ⇒ Object
- #exit_code ⇒ Object
- #exit_code=(value) ⇒ Object
- #has_exposed_artifacts? ⇒ Boolean
- #id_tokens ⇒ Object
- #id_tokens=(_value) ⇒ Object
- #id_tokens? ⇒ Boolean
- #interruptible ⇒ Object
- #interruptible=(_value) ⇒ Object
- #options ⇒ Object
-
#options=(value) ⇒ Object
Should be removed when the column is dropped from p_ci_builds allows deleting data for
degenerate!. - #scoped_user_id ⇒ Object
- #secrets=(_value) ⇒ Object
- #timeout_human_readable_value ⇒ Object
-
#timeout_source_value ⇒ Object
metadata has
unknown_timeout_sourceas default. - #timeout_value ⇒ Object
-
#update_timeout_state ⇒ Object
This method is called from within a Ci::Build state transition; it returns nil/true (success) or false (failure).
- #yaml_variables ⇒ Object
-
#yaml_variables=(value) ⇒ Object
Should be removed when the column is dropped from p_ci_builds allows deleting data for
degenerate!.
Instance Method Details
#artifacts_exposed_as ⇒ Object
137 138 139 |
# File 'app/models/concerns/ci/metadatable.rb', line 137 def artifacts_exposed_as &.exposed_as || .dig(:artifacts, :expose_as) end |
#artifacts_exposed_paths ⇒ Object
141 142 143 |
# File 'app/models/concerns/ci/metadatable.rb', line 141 def artifacts_exposed_paths &.exposed_paths || .dig(:artifacts, :paths) end |
#debug_trace_enabled? ⇒ 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
64 65 66 |
# File 'app/models/concerns/ci/metadatable.rb', line 64 def degenerated? self..blank? end |
#downstream_errors ⇒ Object
145 146 147 |
# File 'app/models/concerns/ci/metadatable.rb', line 145 def downstream_errors .map(&:content).presence || [: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_code ⇒ Object
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
60 61 62 |
# File 'app/models/concerns/ci/metadatable.rb', line 60 def has_exposed_artifacts? artifacts_exposed_as.present? end |
#id_tokens ⇒ Object
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
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
97 98 99 |
# File 'app/models/concerns/ci/metadatable.rb', line 97 def id_tokens? id_tokens.present? end |
#interruptible ⇒ Object
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
182 183 184 |
# File 'app/models/concerns/ci/metadatable.rb', line 182 def interruptible=(_value) raise ActiveRecord::ReadonlyAttributeError, 'This data is read only' end |
#options ⇒ Object
78 79 80 |
# File 'app/models/concerns/ci/metadatable.rb', line 78 def (: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!
168 169 170 171 172 |
# File 'app/models/concerns/ci/metadatable.rb', line 168 def (value) raise ActiveRecord::ReadonlyAttributeError, 'This data is read only' unless value.nil? super end |
#scoped_user_id ⇒ Object
150 151 152 |
# File 'app/models/concerns/ci/metadatable.rb', line 150 def scoped_user_id read_attribute(:scoped_user_id) || [:scoped_user_id] end |
#secrets=(_value) ⇒ Object
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_value ⇒ Object
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_value ⇒ Object
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_value ⇒ Object
116 117 118 |
# File 'app/models/concerns/ci/metadatable.rb', line 116 def timeout_value timeout || &.timeout end |
#update_timeout_state ⇒ Object
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_variables ⇒ Object
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!
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 |