From 5dfbb2fc806023eceb6cfca0597cff3d55c9e6f7 Mon Sep 17 00:00:00 2001 From: mo khan Date: Mon, 22 Sep 2014 19:50:24 -0600 Subject: add a bit of console output and add missing create tmp dir method. --- script/migrate-photos.rb | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'script') diff --git a/script/migrate-photos.rb b/script/migrate-photos.rb index bcc42f32..f41e28b9 100644 --- a/script/migrate-photos.rb +++ b/script/migrate-photos.rb @@ -11,12 +11,18 @@ class Command def run Photo.find_each do |photo| - original = OriginalVersion.new(photo) - storage.download(original.create_key) do |file| - message_bus.publish(:upload_photo, { - photo_id: photo.id, - file_path: move_to_temporary_storage(file.path, File.basename(original.create_key)) - }) + begin + original = OriginalVersion.new(photo) + key = original.create_key + puts "processing #{key}" + storage.download(key) do |file| + bus.publish(:upload_photo, { + photo_id: photo.id, + file_path: move_to_temporary_storage(file.path, File.basename(key)) + }) + end + rescue StandardError => error + puts error.message end end end @@ -28,6 +34,12 @@ class Command FileUtils.mv(temp_file_path, new_path) end end + + def create_tmp_dir + Rails.root.join("tmp/uploads/#{SecureRandom.uuid}").tap do |directory| + system "mkdir -p #{directory}" + end + end end Command.new.run -- cgit v1.2.3