Class: RepositoryCheck::BatchWorker

Inherits:
Object
  • Object
show all
Includes:
ApplicationWorker, 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

Constants included from WorkerAttributes

WorkerAttributes::NAMESPACE_WEIGHTS, WorkerAttributes::VALID_RESOURCE_BOUNDARIES, WorkerAttributes::VALID_URGENCIES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ExclusiveLeaseGuard

#exclusive_lease, #lease_release?, #log_error, #release_lease, #renew_lease!, #try_obtain_lease

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


13
14
15
# File 'app/workers/repository_check/batch_worker.rb', line 13

def shard_name
  @shard_name
end

Instance Method Details

#lease_keyObject


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

def lease_key
  "repository_check_batch_worker:#{shard_name}"
end

#lease_timeoutObject


28
29
30
# File 'app/workers/repository_check/batch_worker.rb', line 28

def lease_timeout
  LEASE_TIMEOUT
end

#perform(shard_name) ⇒ Object


17
18
19
20
21
22
23
24
25
26
# File 'app/workers/repository_check/batch_worker.rb', line 17

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


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/workers/repository_check/batch_worker.rb', line 36

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