Commit 5dfbb2fc

mo khan <mo@mokhan.ca>
2014-09-23 01:50:24
add a bit of console output and add missing create tmp dir method.
1 parent 643c57c
Changed files (1)
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