Class: Ci::PersistentRef

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/ci/persistent_ref.rb

Overview

The persistent pipeline ref to ensure runners can safely fetch source code even if force-push/source-branch-deletion happens.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pipelineObject

Returns the value of attribute pipeline.



10
11
12
# File 'app/models/ci/persistent_ref.rb', line 10

def pipeline
  @pipeline
end

Instance Method Details

#async_deleteObject



45
46
47
48
49
# File 'app/models/ci/persistent_ref.rb', line 45

def async_delete
  return unless should_delete?

  async_delete_refs(path)
end

#createObject



27
28
29
30
31
32
# File 'app/models/ci/persistent_ref.rb', line 27

def create
  create_ref(sha, path)
rescue StandardError => e
  Gitlab::ErrorTracking
    .track_exception(e, pipeline_id: pipeline.id)
end

#deleteObject



34
35
36
37
38
39
40
41
42
43
# File 'app/models/ci/persistent_ref.rb', line 34

def delete
  return unless should_delete?

  delete_refs(path)
rescue Gitlab::Git::Repository::NoRepository
  # no-op
rescue StandardError => e
  Gitlab::ErrorTracking
    .track_exception(e, pipeline_id: pipeline.id)
end

#exist?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
# File 'app/models/ci/persistent_ref.rb', line 16

def exist?
  ref_exists?(path)
rescue StandardError
  false
end

#pathObject



51
52
53
# File 'app/models/ci/persistent_ref.rb', line 51

def path
  "refs/#{Repository::REF_PIPELINES}/#{pipeline.id}"
end

#should_delete?Boolean

This needs to be kept in sync with ‘Ci::Pipeline#after_transition` calling `pipeline.persistent_ref.delete`

Returns:

  • (Boolean)


23
24
25
# File 'app/models/ci/persistent_ref.rb', line 23

def should_delete?
  pipeline.status.to_sym.in?(::Ci::Pipeline.stopped_statuses)
end