Class: DeleteContainerRepositoryWorker

Inherits:
Object
  • Object
show all
Includes:
ApplicationWorker, ExclusiveLeaseGuard
Defined in:
app/workers/delete_container_repository_worker.rb

Overview

rubocop:disable Scalability/IdempotentWorker

Constant Summary collapse

LEASE_TIMEOUT =
1.hour

Constants included from ApplicationWorker

ApplicationWorker::LOGGING_EXTRA_KEY, ApplicationWorker::SAFE_PUSH_BULK_LIMIT

Constants included from WorkerAttributes

WorkerAttributes::DEFAULT_DATA_CONSISTENCY, WorkerAttributes::NAMESPACE_WEIGHTS, WorkerAttributes::VALID_DATA_CONSISTENCIES, WorkerAttributes::VALID_RESOURCE_BOUNDARIES, WorkerAttributes::VALID_URGENCIES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ExclusiveLeaseGuard

#exclusive_lease, #lease_release?, #log_error, #release_lease, #renew_lease!, #try_obtain_lease

Methods included from Gitlab::SidekiqVersioning::Worker

#job_version

Methods included from WorkerContext

#with_context

Instance Attribute Details

#container_repositoryObject (readonly)

Returns the value of attribute container_repository.


16
17
18
# File 'app/workers/delete_container_repository_worker.rb', line 16

def container_repository
  @container_repository
end

Instance Method Details

#lease_keyObject

For ExclusiveLeaseGuard concern


33
34
35
# File 'app/workers/delete_container_repository_worker.rb', line 33

def lease_key
  @lease_key ||= "container_repository:delete:#{container_repository.id}"
end

#lease_timeoutObject

For ExclusiveLeaseGuard concern


38
39
40
# File 'app/workers/delete_container_repository_worker.rb', line 38

def lease_timeout
  LEASE_TIMEOUT
end

#perform(current_user_id, container_repository_id) ⇒ Object


18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/workers/delete_container_repository_worker.rb', line 18

def perform(current_user_id, container_repository_id)
  current_user = User.find_by_id(current_user_id)
  @container_repository = ContainerRepository.find_by_id(container_repository_id)
  project = container_repository&.project

  return unless current_user && container_repository && project

  # If a user accidentally attempts to delete the same container registry in quick succession,
  # this can lead to orphaned tags.
  try_obtain_lease do
    Projects::ContainerRepository::DestroyService.new(project, current_user).execute(container_repository)
  end
end