Class: Packages::Cleanup::ExecutePolicyWorker

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

Constant Summary collapse

COUNTS_KEYS =
%i[
  marked_package_files_total_count
  unique_package_id_and_file_name_total_count
].freeze

Constants included from ApplicationWorker

ApplicationWorker::LOGGING_EXTRA_KEY, ApplicationWorker::SAFE_PUSH_BULK_LIMIT

Constants included from Gitlab::Loggable

Gitlab::Loggable::ANONYMOUS

Constants included from WorkerAttributes

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

Instance Method Summary collapse

Methods included from LimitedCapacity::Worker

#perform, #remove_failed_jobs, #report_prometheus_metrics

Methods included from Gitlab::Loggable

#build_structured_payload

Methods included from Gitlab::SidekiqVersioning::Worker

#job_version

Methods included from WorkerContext

#with_context

Instance Method Details

#max_running_jobsObject



44
45
46
# File 'app/workers/packages/cleanup/execute_policy_worker.rb', line 44

def max_running_jobs
  ::Gitlab::CurrentSettings.package_registry_cleanup_policies_worker_capacity
end

#perform_workObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/workers/packages/cleanup/execute_policy_worker.rb', line 22

def perform_work
  return unless next_policy

  (:project_id, next_policy.project_id)
  result = ::Packages::Cleanup::ExecutePolicyService.new(next_policy).execute

  if result.success?
    timeout = !!result.payload[:timeout]
    counts = result.payload[:counts]
    (:execution_timeout, timeout)
    COUNTS_KEYS.each do |count_key|
      (count_key, counts[count_key])
    end
  end
end

#remaining_work_countObject



38
39
40
41
42
# File 'app/workers/packages/cleanup/execute_policy_worker.rb', line 38

def remaining_work_count
  ::Packages::Cleanup::Policy.runnable
                             .limit(max_running_jobs + 1)
                             .count
end