Class: Ci::Processable

Inherits:
CommitStatus show all
Extended by:
Gitlab::Utils::Override
Includes:
Metadatable, FromUnion, Gitlab::Utils::StrongMemoize
Defined in:
app/models/ci/processable.rb

Overview

This class is a collection of common features between Ci::Build and Ci::Bridge. In gitlab.com/groups/gitlab-org/-/epics/9991, we aim to clarify class naming conventions.

Direct Known Subclasses

Bridge, Build

Constant Summary

Constants included from TaggableQueries

TaggableQueries::MAX_TAGS_IDS, TaggableQueries::TooManyTagsError

Constants included from HasStatus

HasStatus::ACTIVE_STATUSES, HasStatus::ALIVE_STATUSES, HasStatus::AVAILABLE_STATUSES, HasStatus::BLOCKED_STATUS, HasStatus::CANCELABLE_STATUSES, HasStatus::COMPLETED_STATUSES, HasStatus::DEFAULT_STATUS, HasStatus::IGNORED_STATUSES, HasStatus::ORDERED_STATUSES, HasStatus::PASSED_WITH_WARNINGS_STATUSES, HasStatus::STARTED_STATUSES, HasStatus::STATUSES_ENUM, HasStatus::STOPPED_STATUSES, HasStatus::UnknownStatusError

Constants included from Partitionable

Ci::Partitionable::MUTEX

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Instance Attribute Summary

Attributes included from Importable

#imported, #importing

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Methods included from Metadatable

#cancel_gracefully?, #degenerate!, #degenerated?, #enqueue_immediately?, #ensure_metadata, #has_exposed_artifacts?, #id_tokens=, #id_tokens?, #interruptible, #interruptible=, #options, #options=, #set_enqueue_immediately!, #yaml_variables, #yaml_variables=

Methods inherited from CommitStatus

#archived?, #auto_canceled?, #cancelable?, #detailed_status, #duration, #expire_etag_cache!, #group_name, #has_trace?, #importing?, #latest?, #locking_enabled?, locking_enabled?, names, #playable?, #queued_duration, #recoverable?, #resource_parent, #sortable_name, #stage_name, #stuck?, switch_table_names, #to_ability_name, update_as_processed!, #update_older_statuses_retried!

Methods included from TaggableQueries

#tags_ids

Methods included from BulkInsertableAssociations

#bulk_insert_associations!, bulk_inserts_enabled?, with_bulk_insert

Methods included from Presentable

#present

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

Methods included from HasStatus

#active?, #blocked?, #complete?, #incomplete?, #started?

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

.populate_scheduling_type!Object

Old processables may have scheduling_type as nil, so we need to ensure the data exists before using it.



91
92
93
94
95
96
97
98
99
# File 'app/models/ci/processable.rb', line 91

def self.populate_scheduling_type!
  needs = Ci::BuildNeed.scoped_build.select(1)
  where(scheduling_type: nil).update_all(
    "scheduling_type = CASE WHEN (EXISTS (#{needs.to_sql}))
     THEN #{scheduling_types[:dag]}
     ELSE #{scheduling_types[:stage]}
     END"
  )
end

.select_with_aggregated_needs(project) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'app/models/ci/processable.rb', line 77

def self.select_with_aggregated_needs(project)
  aggregated_needs_names = Ci::BuildNeed
    .scoped_build
    .select("ARRAY_AGG(name)")
    .to_sql

  all.select(
    '*',
    "(#{aggregated_needs_names}) as aggregated_needs_names"
  )
end

Instance Method Details

#action?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


139
140
141
# File 'app/models/ci/processable.rb', line 139

def action?
  raise NotImplementedError
end

#aggregated_needs_namesObject



131
132
133
# File 'app/models/ci/processable.rb', line 131

def aggregated_needs_names
  read_attribute(:aggregated_needs_names)
end

#all_dependenciesObject



203
204
205
206
207
# File 'app/models/ci/processable.rb', line 203

def all_dependencies
  strong_memoize(:all_dependencies) do
    dependencies.all
  end
end

#all_met_to_become_pending?Boolean

Returns:

  • (Boolean)


160
161
162
# File 'app/models/ci/processable.rb', line 160

def all_met_to_become_pending?
  super && !with_resource_group?
end

#clone(current_user:, new_job_variables_attributes: []) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/ci/processable.rb', line 110

def clone(current_user:, new_job_variables_attributes: [])
  new_attributes = self.class.clone_accessors.index_with do |attribute|
    public_send(attribute) # rubocop:disable GitlabSecurity/PublicSend
  end

  if persisted_environment.present?
    new_attributes[:metadata_attributes] ||= {}
    new_attributes[:metadata_attributes][:expanded_environment_name] = expanded_environment_name
  end

  new_attributes[:user] = current_user

  self.class.new(new_attributes)
end

#dependency_variablesObject



195
196
197
198
199
200
201
# File 'app/models/ci/processable.rb', line 195

def dependency_variables
  return [] if all_dependencies.empty?

  Gitlab::Ci::Variables::Collection.new.concat(
    Ci::JobVariable.where(job: all_dependencies).dotenv_source
  )
end

#ensure_scheduling_type!Object



187
188
189
190
191
192
193
# File 'app/models/ci/processable.rb', line 187

def ensure_scheduling_type!
  # If this has a scheduling_type, it means all processables in the pipeline already have.
  return if scheduling_type

  pipeline.ensure_scheduling_type!
  reset
end

#expanded_environment_nameObject

Raises:

  • (NotImplementedError)


151
152
153
# File 'app/models/ci/processable.rb', line 151

def expanded_environment_name
  raise NotImplementedError
end

#find_legacy_scheduling_typeObject

scheduling_type column of previous builds/bridges have not been populated, so we calculate this value on runtime when we need it.



175
176
177
178
179
# File 'app/models/ci/processable.rb', line 175

def find_legacy_scheduling_type
  strong_memoize(:find_legacy_scheduling_type) do
    needs.exists? ? :dag : :stage
  end
end

#needs_attributesObject



181
182
183
184
185
# File 'app/models/ci/processable.rb', line 181

def needs_attributes
  strong_memoize(:needs_attributes) do
    needs.map { |need| need.attributes.except('id', 'build_id') }
  end
end

#other_manual_actionsObject



143
144
145
# File 'app/models/ci/processable.rb', line 143

def other_manual_actions
  pipeline.manual_actions.reject { |action| action.name == name }
end

#persisted_environmentObject

Raises:

  • (NotImplementedError)


155
156
157
# File 'app/models/ci/processable.rb', line 155

def persisted_environment
  raise NotImplementedError
end

#retryable?Boolean

Returns:

  • (Boolean)


125
126
127
128
129
# File 'app/models/ci/processable.rb', line 125

def retryable?
  return false if retried? || archived? || deployment_rejected?

  success? || failed? || canceled?
end

#schedulable?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


135
136
137
# File 'app/models/ci/processable.rb', line 135

def schedulable?
  raise NotImplementedError
end

#scheduling_type_dag?Boolean

Overriding scheduling_type enum’s method for nil ‘scheduling_type`s

Returns:

  • (Boolean)


169
170
171
# File 'app/models/ci/processable.rb', line 169

def scheduling_type_dag?
  scheduling_type.nil? ? find_legacy_scheduling_type == :dag : super
end

#whenObject



147
148
149
# File 'app/models/ci/processable.rb', line 147

def when
  read_attribute(:when) || 'on_success'
end

#with_resource_group?Boolean

Returns:

  • (Boolean)


164
165
166
# File 'app/models/ci/processable.rb', line 164

def with_resource_group?
  self.resource_group_id.present?
end