Module: GitGarbageCollectMethods

Extended by:
ActiveSupport::Concern
Included in:
Projects::GitGarbageCollectWorker, Wikis::GitGarbageCollectWorker
Defined in:
app/workers/concerns/git_garbage_collect_methods.rb

Constant Summary collapse

LEASE_TIMEOUT =

Timeout set to 24h

86400

Instance Method Summary collapse

Instance Method Details

#perform(resource_id, task = :gc, lease_key = nil, lease_uuid = nil) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/workers/concerns/git_garbage_collect_methods.rb', line 17

def perform(resource_id, task = :gc, lease_key = nil, lease_uuid = nil)
  resource = find_resource(resource_id)
  lease_key ||= default_lease_key(task, resource)
  active_uuid = get_lease_uuid(lease_key)

  if active_uuid
    return unless active_uuid == lease_uuid

    renew_lease(lease_key, active_uuid)
  else
    lease_uuid = try_obtain_lease(lease_key)

    return unless lease_uuid
  end

  task = task.to_sym

  before_gitaly_call(task, resource)
  gitaly_call(task, resource)

  # Refresh the branch cache in case garbage collection caused a ref lookup to fail
  flush_ref_caches(resource) if gc?(task)

  update_repository_statistics(resource) if task != :pack_refs

  # In case pack files are deleted, release libgit2 cache and open file
  # descriptors ASAP instead of waiting for Ruby garbage collection
  resource.cleanup
ensure
  cancel_lease(lease_key, lease_uuid) if lease_key.present? && lease_uuid.present?
end