Class: Ci::Ref

Inherits:
ApplicationRecord show all
Includes:
AfterCommitQueue, Gitlab::OptimisticLocking
Defined in:
app/models/ci/ref.rb

Constant Summary collapse

FAILING_STATUSES =
%w[failed broken still_failing].freeze

Constants included from Gitlab::OptimisticLocking

Gitlab::OptimisticLocking::MAX_RETRIES

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::OptimisticLocking

log_optimistic_lock_retries, retry_lock, retry_lock_histogram, retry_lock_logger

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

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, nullable_column?, 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 ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Class Method Details

.ensure_for(pipeline) ⇒ Object



36
37
38
# File 'app/models/ci/ref.rb', line 36

def ensure_for(pipeline)
  safe_find_or_create_by(project_id: pipeline.project_id, ref_path: pipeline.source_ref_path)
end

.failing_state?(status_name) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/models/ci/ref.rb', line 40

def failing_state?(status_name)
  FAILING_STATUSES.include?(status_name)
end

Instance Method Details

#artifacts_locked?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/models/ci/ref.rb', line 53

def artifacts_locked?
  self.pipelines.where(locked: :artifacts_locked).exists?
end

#last_finished_pipelineObject



49
50
51
# File 'app/models/ci/ref.rb', line 49

def last_finished_pipeline
  Ci::Pipeline.last_finished_for_ref_id(self.id)
end

#last_finished_pipeline_idObject



45
46
47
# File 'app/models/ci/ref.rb', line 45

def last_finished_pipeline_id
  last_finished_pipeline&.id
end

#last_successful_ci_source_pipelineObject



70
71
72
# File 'app/models/ci/ref.rb', line 70

def last_successful_ci_source_pipeline
  pipelines.ci_sources.success.order(id: :desc).first
end

#last_unlockable_ci_source_pipelineObject



74
75
76
# File 'app/models/ci/ref.rb', line 74

def last_unlockable_ci_source_pipeline
  pipelines.ci_sources.with_unlockable_status.order(id: :desc).first
end

#update_status_by!(pipeline) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/ci/ref.rb', line 57

def update_status_by!(pipeline)
  retry_lock(self, name: 'ci_ref_update_status_by') do
    next unless last_finished_pipeline_id == pipeline.id

    case pipeline.status
    when 'success' then self.succeed
    when 'failed' then self.do_fail
    end

    self.status_name
  end
end