Class: Ci::Processable

Inherits:
CommitStatus show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/models/ci/processable.rb

Direct Known Subclasses

Bridge, Build

Constant Summary

Constants included from HasStatus

HasStatus::ACTIVE_STATUSES, HasStatus::AVAILABLE_STATUSES, HasStatus::BLOCKED_STATUS, HasStatus::COMPLETED_STATUSES, HasStatus::DEFAULT_STATUS, HasStatus::EXCLUDE_IGNORED_STATUSES, HasStatus::ORDERED_STATUSES, HasStatus::PASSED_WITH_WARNINGS_STATUSES, HasStatus::STARTED_STATUSES, HasStatus::STATUSES_ENUM, HasStatus::UnknownStatusError

Instance Attribute Summary

Attributes included from Importable

#imported, #importing

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods inherited from CommitStatus

#all_met_to_become_pending?, #any_unmet_prerequisites?, #archived?, #auto_canceled?, #cancelable?, #detailed_status, #duration, #failed_but_allowed?, #group_name, #has_trace?, #importing?, #latest?, locking_enabled?, #locking_enabled?, names, #playable?, #recoverable?, #requires_resource?, #retryable?, #sortable_name, #stuck?, update_as_processed!

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?, #started?

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

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.


37
38
39
40
41
42
43
44
45
# File 'app/models/ci/processable.rb', line 37

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


23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/ci/processable.rb', line 23

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)

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

def action?
  raise NotImplementedError
end

#aggregated_needs_namesObject


56
57
58
# File 'app/models/ci/processable.rb', line 56

def aggregated_needs_names
  read_attribute(:aggregated_needs_names)
end

#ensure_scheduling_type!Object


99
100
101
102
103
104
105
# File 'app/models/ci/processable.rb', line 99

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)

72
73
74
# File 'app/models/ci/processable.rb', line 72

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.


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

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

#needs_attributesObject


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

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

#schedulable?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)

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

def schedulable?
  raise NotImplementedError
end

#scheduling_type_dag?Boolean

Overriding scheduling_type enum's method for nil `scheduling_type`s

Returns:

  • (Boolean)

81
82
83
# File 'app/models/ci/processable.rb', line 81

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

#scoped_variables_hashObject

Raises:

  • (NotImplementedError)

76
77
78
# File 'app/models/ci/processable.rb', line 76

def scoped_variables_hash
  raise NotImplementedError
end

#whenObject


68
69
70
# File 'app/models/ci/processable.rb', line 68

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