Class: Ci::Stage

Inherits:
ApplicationRecord show all
Extended by:
Gitlab::Ci::Model
Includes:
HasStatus, Gitlab::OptimisticLocking, Importable
Defined in:
app/models/ci/stage.rb

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

Instance Method Summary collapse

Methods included from Gitlab::Ci::Model

model_name, table_name_prefix

Methods included from Gitlab::OptimisticLocking

retry_lock

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

Instance Method Details

#detailed_status(current_user) ⇒ Object


130
131
132
133
134
# File 'app/models/ci/stage.rb', line 130

def detailed_status(current_user)
  Gitlab::Ci::Status::Stage::Factory
    .new(self, current_user)
    .fabricate!
end

#groupsObject


111
112
113
# File 'app/models/ci/stage.rb', line 111

def groups
  @groups ||= Ci::Group.fabricate(project, self)
end

#has_warnings?Boolean

Returns:

  • (Boolean)

115
116
117
# File 'app/models/ci/stage.rb', line 115

def has_warnings?
  number_of_warnings > 0
end

#latest_stage_statusObject


140
141
142
# File 'app/models/ci/stage.rb', line 140

def latest_stage_status
  statuses.latest.composite_status || 'skipped'
end

#manual_playable?Boolean

Returns:

  • (Boolean)

136
137
138
# File 'app/models/ci/stage.rb', line 136

def manual_playable?
  blocked? || skipped?
end

#number_of_warningsObject


119
120
121
122
123
124
125
126
127
128
# File 'app/models/ci/stage.rb', line 119

def number_of_warnings
  BatchLoader.for(id).batch(default_value: 0) do |stage_ids, loader|
    ::Ci::Build.where(stage_id: stage_ids)
      .latest
      .failed_but_allowed
      .group(:stage_id)
      .count
      .each { |id, amount| loader.call(id, amount) }
  end
end

#set_status(new_status) ⇒ Object


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/models/ci/stage.rb', line 86

def set_status(new_status)
  retry_optimistic_lock(self) do
    case new_status
    when 'created' then nil
    when 'waiting_for_resource' then request_resource
    when 'preparing' then prepare
    when 'pending' then enqueue
    when 'running' then run
    when 'success' then succeed
    when 'failed' then drop
    when 'canceled' then cancel
    when 'manual' then block
    when 'scheduled' then delay
    when 'skipped', nil then skip
    else
      raise Ci::HasStatus::UnknownStatusError,
            "Unknown status `#{new_status}`"
    end
  end
end

#update_legacy_statusObject


107
108
109
# File 'app/models/ci/stage.rb', line 107

def update_legacy_status
  set_status(latest_stage_status.to_s)
end