2017-09-06 05:16:26 +00:00
|
|
|
class ProjectMigrateHashedStorageWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
include DedicatedSidekiqQueue
|
|
|
|
|
2017-11-22 05:35:53 +00:00
|
|
|
LEASE_TIMEOUT = 30.seconds.to_i
|
|
|
|
|
2017-09-06 05:16:26 +00:00
|
|
|
def perform(project_id)
|
|
|
|
project = Project.find_by(id: project_id)
|
|
|
|
return if project.nil? || project.pending_delete?
|
|
|
|
|
2017-11-22 15:29:03 +00:00
|
|
|
uuid = lease_for(project_id).try_obtain
|
2017-11-22 05:35:53 +00:00
|
|
|
if uuid
|
|
|
|
::Projects::HashedStorageMigrationService.new(project, logger).execute
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
rescue => ex
|
2017-11-22 15:29:03 +00:00
|
|
|
cancel_lease_for(project_id, uuid) if uuid
|
2017-11-22 05:35:53 +00:00
|
|
|
raise ex
|
|
|
|
end
|
|
|
|
|
2017-11-22 15:29:03 +00:00
|
|
|
def lease_for(project_id)
|
|
|
|
Gitlab::ExclusiveLease.new(lease_key(project_id), timeout: LEASE_TIMEOUT)
|
2017-11-22 05:35:53 +00:00
|
|
|
end
|
|
|
|
|
2017-11-22 15:29:03 +00:00
|
|
|
private
|
|
|
|
|
2017-11-22 05:35:53 +00:00
|
|
|
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)
|
2017-09-06 05:16:26 +00:00
|
|
|
end
|
|
|
|
end
|