Class: RepositoryCheck::BatchWorker

Inherits:
Object
  • Object
show all
Includes:
ApplicationWorker, CronjobChildWorker, ExclusiveLeaseGuard, RepositoryCheckQueue
Defined in:
app/workers/repository_check/batch_worker.rb

Overview

rubocop:disable Scalability/IdempotentWorker

Constant Summary collapse

RUN_TIME =
3600
BATCH_SIZE =
10_000
LEASE_TIMEOUT =
1.hour

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 Attribute Summary collapse

Instance Method Summary collapse

Methods included from ExclusiveLeaseGuard

#exclusive_lease, #lease_release?, #lease_taken_log_level, #lease_taken_message, #log_lease_taken, #release_lease, #renew_lease!, #try_obtain_lease

Methods included from Gitlab::Loggable

#build_structured_payload

Methods included from Gitlab::SidekiqVersioning::Worker

#job_version

Methods included from WorkerContext

#with_context

Instance Attribute Details

#shard_nameObject (readonly)

Returns the value of attribute shard_name.



18
19
20
# File 'app/workers/repository_check/batch_worker.rb', line 18

def shard_name
  @shard_name
end

Instance Method Details

#lease_keyObject



37
38
39
# File 'app/workers/repository_check/batch_worker.rb', line 37

def lease_key
  "repository_check_batch_worker:#{shard_name}"
end

#lease_timeoutObject



33
34
35
# File 'app/workers/repository_check/batch_worker.rb', line 33

def lease_timeout
  LEASE_TIMEOUT
end

#perform(shard_name) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'app/workers/repository_check/batch_worker.rb', line 22

def perform(shard_name)
  @shard_name = shard_name

  return unless Gitlab::CurrentSettings.repository_checks_enabled
  return unless Gitlab::ShardHealthCache.healthy_shard?(shard_name)

  try_obtain_lease do
    perform_repository_checks
  end
end

#perform_repository_checksObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/workers/repository_check/batch_worker.rb', line 41

def perform_repository_checks
  start = Time.current

  # This loop will break after a little more than one hour ('a little
  # more' because `git fsck` may take a few minutes), or if it runs out of
  # projects to check. By default sidekiq-cron will start a new
  # RepositoryCheckWorker each hour so that as long as there are repositories to
  # check, only one (or two) will be checked at a time.
  project_ids.each do |project_id|
    break if Time.current - start >= RUN_TIME

    next unless try_obtain_lease_for_project(project_id)

    SingleRepositoryWorker.new.perform(project_id)
  end
end