diff options
author | Gabriel Mazetto <brodock@gmail.com> | 2017-11-22 06:35:53 +0100 |
---|---|---|
committer | Gabriel Mazetto <brodock@gmail.com> | 2017-11-23 14:19:36 +0100 |
commit | 65bd6868d014e23c21e4d5ecff468124b2c72f4c (patch) | |
tree | 16a9413dfe0564e0454e924b5974308f7b5488c5 /app/workers/project_migrate_hashed_storage_worker.rb | |
parent | 4b87c1afaa652d72fa6aeeb4fe52fa3883e2f4c8 (diff) | |
download | gitlab-ce-65bd6868d014e23c21e4d5ecff468124b2c72f4c.tar.gz |
Codestyle changes and Added Exclusive Lease to hashed storage migration
Diffstat (limited to 'app/workers/project_migrate_hashed_storage_worker.rb')
-rw-r--r-- | app/workers/project_migrate_hashed_storage_worker.rb | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/app/workers/project_migrate_hashed_storage_worker.rb b/app/workers/project_migrate_hashed_storage_worker.rb index ca276d7801c..e3ecd6bc950 100644 --- a/app/workers/project_migrate_hashed_storage_worker.rb +++ b/app/workers/project_migrate_hashed_storage_worker.rb @@ -2,10 +2,34 @@ class ProjectMigrateHashedStorageWorker include Sidekiq::Worker include DedicatedSidekiqQueue + LEASE_TIMEOUT = 30.seconds.to_i + def perform(project_id) project = Project.find_by(id: project_id) return if project.nil? || project.pending_delete? - ::Projects::HashedStorageMigrationService.new(project, logger).execute + uuid = try_obtain_lease_for(project_id) + if uuid + ::Projects::HashedStorageMigrationService.new(project, logger).execute + else + false + end + rescue => ex + cancel_lease_for(project_id, uuid) + raise ex + end + + private + + def try_obtain_lease_for(project_id) + Gitlab::ExclusiveLease.new(lease_key(project_id), timeout: LEASE_TIMEOUT).try_obtain + end + + def lease_key(project_id) + "project_migrate_hashed_storage_worker:#{project_id}" + end + + def cancel_lease_for(project_id, uuid) + Gitlab::ExclusiveLease.cancel(lease_key(project_id), uuid) end end |