Class: Ci::Stage

Constant Summary

Constants included from Gitlab::OptimisticLocking

Gitlab::OptimisticLocking::MAX_RETRIES

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

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

Instance Method Summary collapse

Methods included from Presentable

#present

Methods included from Gitlab::OptimisticLocking

log_optimistic_lock_retries, retry_lock, retry_lock_histogram, retry_lock_logger

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

Instance Method Details

#detailed_status(current_user) ⇒ Object



150
151
152
153
154
# File 'app/models/ci/stage.rb', line 150

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

#groupsObject



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

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

#has_warnings?Boolean

Returns:

  • (Boolean)


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

def has_warnings?
  number_of_warnings > 0
end

#latest_stage_statusObject

This will be removed with ci_remove_ensure_stage_service



161
162
163
# File 'app/models/ci/stage.rb', line 161

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

#manual_playable?Boolean

Returns:

  • (Boolean)


156
157
158
# File 'app/models/ci/stage.rb', line 156

def manual_playable?
  blocked? || skipped?
end

#number_of_warningsObject



139
140
141
142
143
144
145
146
147
148
# File 'app/models/ci/stage.rb', line 139

def number_of_warnings
  BatchLoader.for(id).batch(default_value: 0) do |stage_ids, loader|
    ::CommitStatus.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



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/models/ci/stage.rb', line 106

def set_status(new_status)
  retry_optimistic_lock(self, name: 'ci_stage_set_status') 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

This will be removed with ci_remove_ensure_stage_service



127
128
129
# File 'app/models/ci/stage.rb', line 127

def update_legacy_status
  set_status(latest_stage_status.to_s)
end