Module: UpdateRepositoryStorageWorker
- Extended by:
- ActiveSupport::Concern
- Includes:
- ApplicationWorker
- Defined in:
- app/workers/concerns/update_repository_storage_worker.rb
Constant Summary collapse
- LEASE_TIMEOUT =
30.minutes.to_i
Constants included from ApplicationWorker
ApplicationWorker::LOGGING_EXTRA_KEY, ApplicationWorker::SAFE_PUSH_BULK_LIMIT
Constants included from Gitlab::Loggable
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
Methods included from Gitlab::SidekiqVersioning::Worker
Methods included from WorkerContext
Instance Method Details
#perform(repository_storage_move_id) ⇒ Object
16 17 18 19 20 21 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 |
# File 'app/workers/concerns/update_repository_storage_worker.rb', line 16 def perform(repository_storage_move_id) repository_storage_move = find_repository_storage_move(repository_storage_move_id) container_id = repository_storage_move.container_id # Use exclusive lock to prevent multiple storage migrations at the same time # # Note: instead of using a randomly generated `uuid`, we provide a worker jid value. # That will allow to track a worker that requested a lease. lease_key = [self.class.name.underscore, container_id].join(':') exclusive_lease = Gitlab::ExclusiveLease.new(lease_key, uuid: jid, timeout: LEASE_TIMEOUT) lease = exclusive_lease.try_obtain if lease begin update_repository_storage(repository_storage_move) ensure exclusive_lease.cancel end else # If there is an ongoing storage migration, then the current one should be marked as failed repository_storage_move.do_fail! # A special case # Sidekiq can receive an interrupt signal during the processing. # It kills existing workers and reschedules their jobs using the same jid. # But it can cause a situation when the migration is only half complete (see https://gitlab.com/gitlab-org/gitlab/-/issues/429049#note_1635650597) # # Here we detect this case and release the lock. uuid = Gitlab::ExclusiveLease.get_uuid(lease_key) exclusive_lease.cancel if uuid == jid end end |