Class: ContainerExpirationPolicies::CleanupContainerRepositoryWorker

Inherits:
Object
  • Object
show all
Includes:
ApplicationWorker, Gitlab::Utils::StrongMemoize, LimitedCapacity::Worker
Defined in:
app/workers/container_expiration_policies/cleanup_container_repository_worker.rb

Constant Summary collapse

LOG_ON_DONE_FIELDS =
%i[
  cleanup_status
  cleanup_tags_service_original_size
  cleanup_tags_service_before_truncate_size
  cleanup_tags_service_after_truncate_size
  cleanup_tags_service_cached_tags_count
  cleanup_tags_service_before_delete_size
  cleanup_tags_service_deleted_size
].freeze

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 Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods included from LimitedCapacity::Worker

#perform, #remove_failed_jobs, #report_prometheus_metrics

Methods included from Gitlab::SidekiqVersioning::Worker

#job_version

Methods included from WorkerContext

#with_context

Instance Method Details

#max_running_jobsObject


46
47
48
# File 'app/workers/container_expiration_policies/cleanup_container_repository_worker.rb', line 46

def max_running_jobs
  ::Gitlab::CurrentSettings.container_registry_expiration_policies_worker_capacity
end

#perform_workObject


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/workers/container_expiration_policies/cleanup_container_repository_worker.rb', line 29

def perform_work
  return unless container_repository

  (:container_repository_id, container_repository.id)
  (:project_id, project.id)

  unless allowed_to_run?
    container_repository.cleanup_unscheduled!
    (:cleanup_status, :skipped)
    return
  end

  result = ContainerExpirationPolicies::CleanupService.new(container_repository)
                                                      .execute
  log_on_done(result)
end

#remaining_work_countObject


50
51
52
53
54
55
56
# File 'app/workers/container_expiration_policies/cleanup_container_repository_worker.rb', line 50

def remaining_work_count
  count = cleanup_scheduled_count

  return count if count > max_running_jobs

  count + cleanup_unfinished_count
end