Class: Ci::Ref

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

Constant Summary collapse

FAILING_STATUSES =
%w[failed broken still_failing].freeze

Class Method Summary collapse

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 AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

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

.ensure_for(pipeline) ⇒ Object


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

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)

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

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

Instance Method Details

#last_finished_pipeline_idObject


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

def last_finished_pipeline_id
  Ci::Pipeline.last_finished_for_ref_id(self.id)&.id
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) 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