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

Constants included from WorkerAttributes

WorkerAttributes::NAMESPACE_WEIGHTS, 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


12
13
14
# File 'app/workers/delete_container_repository_worker.rb', line 12

def container_repository
  @container_repository
end

Instance Method Details

#lease_keyObject

For ExclusiveLeaseGuard concern


31
32
33
# File 'app/workers/delete_container_repository_worker.rb', line 31

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

#lease_timeoutObject

For ExclusiveLeaseGuard concern


36
37
38
# File 'app/workers/delete_container_repository_worker.rb', line 36

def lease_timeout
  LEASE_TIMEOUT
end

#perform(current_user_id, container_repository_id) ⇒ Object

rubocop: disable CodeReuse/ActiveRecord


15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/workers/delete_container_repository_worker.rb', line 15

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