Class: LooseForeignKeys::CleanupWorker

Inherits:
Object
  • Object
show all
Includes:
ApplicationWorker, CronjobQueue, Gitlab::ExclusiveLeaseHelpers
Defined in:
app/workers/loose_foreign_keys/cleanup_worker.rb

Constant Summary

Constants included from Gitlab::ExclusiveLeaseHelpers

Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError

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::ExclusiveLeaseHelpers

#in_lock

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



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/workers/loose_foreign_keys/cleanup_worker.rb', line 14

def perform
  connection_name, base_model = current_connection_name_and_base_model
  modification_tracker, turbo_mode = initialize_modification_tracker_for(connection_name)

  # Add small buffer on MAX_RUNTIME to account for single long running
  # query or extra worker time after the cleanup.
  lock_ttl = modification_tracker.max_runtime + 10.seconds

  in_lock(self.class.name.underscore, ttl: lock_ttl, retries: 0) do
    stats = {}

    Gitlab::Database::SharedModel.using_connection(base_model.connection) do
      stats = ProcessDeletedRecordsService.new(
        connection: base_model.connection,
        modification_tracker: modification_tracker
      ).execute
      stats[:connection] = connection_name
      stats[:turbo_mode] = turbo_mode
    end

    (:stats, stats)
  end
end