Raises error when migration cannot happen so job is cancelled
This commit is contained in:
parent
f0f6a237d7
commit
9fd31eb469
2 changed files with 5 additions and 6 deletions
|
@ -1,5 +1,7 @@
|
|||
module Projects
|
||||
module HashedStorage
|
||||
AttachmentMigrationError = Class.new(StandardError)
|
||||
|
||||
class MigrateAttachmentsService < BaseService
|
||||
attr_reader :logger
|
||||
|
||||
|
@ -27,7 +29,7 @@ module Projects
|
|||
|
||||
if File.exist?(new_path)
|
||||
logger.error("Cannot migrate attachments from '#{old_path}' to '#{new_path}', target path already exist (PROJECT_ID=#{project.id})")
|
||||
return
|
||||
raise AttachmentMigrationError, "Target path '#{new_path}' already exist"
|
||||
end
|
||||
|
||||
# Create hashed storage base path folder
|
||||
|
|
|
@ -49,13 +49,10 @@ describe Projects::HashedStorage::MigrateAttachmentsService do
|
|||
FileUtils.mkdir_p(base_path(hashed_storage))
|
||||
end
|
||||
|
||||
it 'skips moving the file and goes to next' do
|
||||
it 'raises AttachmentMigrationError' do
|
||||
expect(FileUtils).not_to receive(:mv).with(base_path(legacy_storage), base_path(hashed_storage))
|
||||
|
||||
service.execute
|
||||
|
||||
expect(File.exist?(base_path(legacy_storage))).to be_truthy
|
||||
expect(File.file?(old_path)).to be_truthy
|
||||
expect { service.execute }.to raise_error(Projects::HashedStorage::AttachmentMigrationError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue