diff options
Diffstat (limited to 'app/workers/hashed_storage/project_rollback_worker.rb')
-rw-r--r-- | app/workers/hashed_storage/project_rollback_worker.rb | 33 |
1 files changed, 6 insertions, 27 deletions
diff --git a/app/workers/hashed_storage/project_rollback_worker.rb b/app/workers/hashed_storage/project_rollback_worker.rb index c6ac76a1674..55e1d7ab23e 100644 --- a/app/workers/hashed_storage/project_rollback_worker.rb +++ b/app/workers/hashed_storage/project_rollback_worker.rb @@ -1,47 +1,26 @@ # frozen_string_literal: true module HashedStorage - class ProjectRollbackWorker + class ProjectRollbackWorker < BaseWorker include ApplicationWorker - LEASE_TIMEOUT = 30.seconds.to_i - queue_namespace :hashed_storage + attr_reader :project_id + # rubocop: disable CodeReuse/ActiveRecord def perform(project_id, old_disk_path = nil) - uuid = lease_for(project_id).try_obtain + @project_id = project_id # we need to set this in order to create the lease_key - if uuid + try_obtain_lease do project = Project.without_deleted.find_by(id: project_id) - return unless project + break unless project old_disk_path ||= project.disk_path ::Projects::HashedStorage::RollbackService.new(project, old_disk_path, logger: logger).execute - else - return false end - - ensure - cancel_lease_for(project_id, uuid) if uuid end - # rubocop: enable CodeReuse/ActiveRecord - - def lease_for(project_id) - Gitlab::ExclusiveLease.new(lease_key(project_id), timeout: LEASE_TIMEOUT) - end - - private - - def lease_key(project_id) - # we share the same lease key for both migration and rollback so they don't run simultaneously - "#{ProjectMigrateWorker::LEASE_KEY_SEGMENT}:#{project_id}" - end - - def cancel_lease_for(project_id, uuid) - Gitlab::ExclusiveLease.cancel(lease_key(project_id), uuid) - end end end |