Class: UserStatusCleanup::BatchWorker

Inherits:
Object
  • Object
show all
Includes:
ApplicationWorker, CronjobQueue
Defined in:
app/workers/user_status_cleanup/batch_worker.rb

Overview

This worker will run every minute to look for user status records to clean up.

Constant Summary collapse

MAX_RUNTIME =

Avoid running too many UPDATE queries at once

30.seconds

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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/workers/user_status_cleanup/batch_worker.rb', line 21

def perform
  return unless UserStatus.scheduled_for_cleanup.exists?

  start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)

  loop do
    result = Users::BatchStatusCleanerService.execute
    break if result[:deleted_rows] < Users::BatchStatusCleanerService::BATCH_SIZE

    current_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)

    break if (current_time - start_time) > MAX_RUNTIME
  end
end