Class: RemoveUnacceptedMemberInvitesWorker

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

Overview

rubocop:disable Scalability/IdempotentWorker

Constant Summary collapse

EXPIRATION_THRESHOLD =
90.days
BATCH_SIZE =
10_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_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



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

def perform
  # We need to check for user_id IS NULL because we have accepted invitations
  # in the database where we did not clear the invite_token. We do not
  # want to accidentally delete those members.
  loop do
    # rubocop: disable CodeReuse/ActiveRecord
    inner_query = Member
                    .select(:id)
                    .invite
                    .created_before(EXPIRATION_THRESHOLD.ago)
                    .where(user_id: nil)
                    .limit(BATCH_SIZE)

    records_deleted = Member.where(id: inner_query).delete_all
    # rubocop: enable CodeReuse/ActiveRecord

    break if records_deleted == 0
  end
end