Class: Packages::Cleanup::DeleteOrphanedDependenciesWorker

Inherits:
Object
  • Object
show all
Includes:
ApplicationWorker, CronjobQueue
Defined in:
app/workers/packages/cleanup/delete_orphaned_dependencies_worker.rb

Constant Summary collapse

MAX_RUN_TIME =

This cron worker is executed at an interval of 10 minutes and should not run for more than 2 minutes nor process more than 10 batches.

2.minutes
MAX_BATCHES =
10
BATCH_SIZE =
100
LAST_PROCESSED_PACKAGES_DEPENDENCY_REDIS_KEY =
'last_processed_packages_dependency_id'
REDIS_EXPIRATION_TIME =
2.hours.to_i

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 Gitlab::Loggable

#build_structured_payload

Methods included from Gitlab::SidekiqVersioning::Worker

#job_version

Methods included from WorkerContext

#with_context

Instance Method Details

#performObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/workers/packages/cleanup/delete_orphaned_dependencies_worker.rb', line 22

def perform
  start_time

  dependency_id = last_processed_dependency_id
  batches_count = 0
  deleted_rows_count = 0

  ::Packages::Dependency.id_in(dependency_id..).each_batch(of: BATCH_SIZE) do |batch|
    batches_count += 1
    deleted_rows_count += batch.orphaned.delete_all

    if batches_count == MAX_BATCHES || over_time?
      save_last_processed_dependency_id(batch.maximum(:id))
      break
    end
  end

  (deleted_rows_count)
  reset_last_processed_dependency_id if batches_count < MAX_BATCHES && !over_time?
end