Class: RepositoryCheck::BatchWorker
- Inherits:
-
Object
- Object
- RepositoryCheck::BatchWorker
- 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, ApplicationWorker::SAFE_PUSH_BULK_LIMIT
Constants included from Gitlab::Loggable
Constants included from WorkerAttributes
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
-
#shard_name ⇒ Object
readonly
Returns the value of attribute shard_name.
Instance Method Summary collapse
- #lease_key ⇒ Object
- #lease_timeout ⇒ Object
- #perform(shard_name) ⇒ Object
- #perform_repository_checks ⇒ Object
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
Methods included from Gitlab::SidekiqVersioning::Worker
Methods included from WorkerContext
Instance Attribute Details
#shard_name ⇒ Object (readonly)
Returns the value of attribute shard_name.
17 18 19 |
# File 'app/workers/repository_check/batch_worker.rb', line 17 def shard_name @shard_name end |
Instance Method Details
#lease_key ⇒ Object
36 37 38 |
# File 'app/workers/repository_check/batch_worker.rb', line 36 def lease_key "repository_check_batch_worker:#{shard_name}" end |
#lease_timeout ⇒ Object
32 33 34 |
# File 'app/workers/repository_check/batch_worker.rb', line 32 def lease_timeout LEASE_TIMEOUT end |
#perform(shard_name) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'app/workers/repository_check/batch_worker.rb', line 21 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_checks ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/workers/repository_check/batch_worker.rb', line 40 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 |