2018-11-08 19:23:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
class ProjectMigrateHashedStorageWorker
|
|
|
|
include ApplicationWorker
|
|
|
|
|
|
|
|
LEASE_TIMEOUT = 30.seconds.to_i
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-11-18 11:00:15 +05:30
|
|
|
def perform(project_id, old_disk_path = nil)
|
2018-03-17 18:26:18 +05:30
|
|
|
project = Project.find_by(id: project_id)
|
|
|
|
return if project.nil? || project.pending_delete?
|
|
|
|
|
|
|
|
uuid = lease_for(project_id).try_obtain
|
|
|
|
if uuid
|
2018-11-18 11:00:15 +05:30
|
|
|
::Projects::HashedStorageMigrationService.new(project, old_disk_path || project.full_path, logger: logger).execute
|
2018-03-17 18:26:18 +05:30
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
rescue => ex
|
|
|
|
cancel_lease_for(project_id, uuid) if uuid
|
|
|
|
raise ex
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
def lease_for(project_id)
|
|
|
|
Gitlab::ExclusiveLease.new(lease_key(project_id), timeout: LEASE_TIMEOUT)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
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
|