Class: Authn::DataRetention::AuthenticationEventArchiveWorker

Inherits:
Object
  • Object
show all
Includes:
ApplicationWorker, CronjobQueue
Defined in:
app/workers/authn/data_retention/authentication_event_archive_worker.rb

Constant Summary collapse

MAX_RUNTIME =
3.minutes
REQUEUE_DELAY =
3.minutes
ITERATION_DELAY =
0.1
BATCH_SIZE =
10_000
SUB_BATCH_SIZE =
1_000

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_CONCURRENCY_LIMIT_PERCENTAGE_BY_URGENCY, WorkerAttributes::DEFAULT_DATA_CONSISTENCY, WorkerAttributes::DEFAULT_DATA_CONSISTENCY_PER_DB, WorkerAttributes::DEFAULT_DEFER_DELAY, WorkerAttributes::LOAD_BALANCED_DATA_CONSISTENCIES, 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

#perform(cursor = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/workers/authn/data_retention/authentication_event_archive_worker.rb', line 22

def perform(cursor = nil)
  return unless Gitlab::CurrentSettings.authn_data_retention_cleanup_enabled?
  return unless Feature.enabled?(:archive_authentication_events, :instance)

  runtime_limiter = Gitlab::Metrics::RuntimeLimiter.new(MAX_RUNTIME)
  total_deleted_count = 0

  # rubocop: disable CodeReuse/ActiveRecord -- not a useful scope for re-use
  AuthenticationEvent.where('id > ?', cursor.to_i).each_batch(of: BATCH_SIZE) do |batch|
    # rubocop: enable CodeReuse/ActiveRecord
    last_id_in_batch = batch.last.id

    batch.each_batch(of: SUB_BATCH_SIZE) do |sub_batch|
      events_to_delete = sub_batch

      count = delete_old_events(events_to_delete)

      total_deleted_count += count

      log_deleted(count)

      sleep ITERATION_DELAY
    end

    if runtime_limiter.over_time?
      self.class.perform_in(REQUEUE_DELAY, last_id_in_batch)
      break
    end
  end

  (:result, {
    over_time: runtime_limiter.was_over_time?,
    total_deleted: total_deleted_count,
    cutoff_time: retention_period_cutoff
  })
end