fix(migrate_to_s3): more errors rescued and log failures to yaml file

parent 8de6b692
Pipeline #89636 canceled with stage
in 5 minutes and 1 second
......@@ -12,12 +12,6 @@ AllCops:
- 'db/schema.rb'
- 'doc/**/*'
- 'tmp/**/*'
<<<<<<< HEAD
=======
- 'doc/**/*'
- vendor/**/*
- Rakefile
>>>>>>> 15382407e (chore(linting): autocorrect the exclusions that make sense and regenerate rubocop todo)
- config/boot.rb
- Rakefile
- vendor/**/*
......
This diff is collapsed.
set :application, 'AOZ-003'
set :repo_url, 'git@git.panter.ch:open-source/aoz-003.git'
append :linked_files, '.env'
append :linked_dirs, 'public/system'
append :linked_dirs, 'public/system', 'storage'
......@@ -29,7 +29,11 @@ Rails.application.configure do
end
# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local
config.active_storage.service = if ENV.fetch('GOOGLE_PROJECT_ID', nil).present?
:google
else
:local
end
## in order to activate letter_opener uncomment this line
# config.action_mailer.delivery_method = :letter_opener
......
require 'yaml'
namespace :active_storage do
desc 'ActiveStorage actions'
task move_paperclip_files: :environment do
......@@ -31,6 +33,8 @@ namespace :active_storage do
puts "#{ActiveStorage::Blob.count} Blobs to go..."
@failed_files = { failed: [] }
ActiveStorage::Blob.find_each do |blob|
print '.'
file = Tempfile.new("file#{Time.now.to_f}")
......@@ -41,13 +45,33 @@ namespace :active_storage do
to_service.upload(blob.key, file, checksum: checksum)
file.close
file.unlink
rescue ActiveStorage::IntegrityError
puts "Rescued by ActiveStorage::IntegrityError statement. ID: #{blob.id} / Key: #{blob.key}"
@failed_files[:failed] << { id: blob.id, key: blob.key, checksum: blob.checksum, error: 'ActiveStorage::IntegrityError' }
File.open('failed_files.yml', 'w') {|f| f.write(@failed_files.to_yaml ) } #Store
next
rescue Google::Cloud::InvalidArgumentError
puts "Rescued by Google::Cloud::InvalidArgumentError statement. ID: #{blob.id} / Key: #{blob.key}"
@failed_files[:failed] << { id: blob.id, key: blob.key, checksum: blob.checksum, error: 'Google::Cloud::InvalidArgumentError' }
File.open('failed_files.yml', 'w') {|f| f.write(@failed_files.to_yaml ) } #Store
next
rescue Google::Apis::ClientError
puts "Rescued by Google::Apis::ClientError statement. ID: #{blob.id} / Key: #{blob.key}"
@failed_files[:failed] << { id: blob.id, key: blob.key, checksum: blob.checksum, error: 'Google::Apis::ClientError' }
File.open('failed_files.yml', 'w') {|f| f.write(@failed_files.to_yaml ) } #Store
next
rescue Errno::ENOENT
puts "Rescued by Errno::ENOENT statement. ID: #{blob.id} / Key: #{blob.key}"
@failed_files[:failed] << { id: blob.id, key: blob.key, checksum: blob.checksum, error: 'Errno::ENOENT' }
File.open('failed_files.yml', 'w') {|f| f.write(@failed_files.to_yaml ) } #Store
next
rescue ActiveStorage::FileNotFoundError
puts "Rescued by FileNotFoundError. ID: #{blob.id} / Key: #{blob.key}"
@failed_files[:failed] << { id: blob.id, key: blob.key, checksum: blob.checksum, error: 'ActiveStorage::FileNotFoundError' }
File.open('failed_files.yml', 'w') {|f| f.write(@failed_files.to_yaml ) } #Store
next
end
File.open('failed_files.yml', 'w') {|f| f.write(@failed_files.to_yaml ) } #Store
end
task migrate_to_s3: :environment do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment