From 86c2686b9a283daaf3bdae42d08006eed202b0e5 Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Mon, 17 Jan 2011 15:48:37 -0800 Subject: [PATCH] a little begin rescue magic for uploading to s3 --- lib/tasks/migrations.rake | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/tasks/migrations.rake b/lib/tasks/migrations.rake index 007595314..4262bd15d 100644 --- a/lib/tasks/migrations.rake +++ b/lib/tasks/migrations.rake @@ -69,11 +69,22 @@ namespace :migrations do connection = Aws::S3.new( AppConfig[:s3_key], AppConfig[:s3_secret]) bucket = connection.bucket('joindiaspora') dir_name = File.dirname(__FILE__) + "/../../public/uploads/images/" + + count = Dir.foreach(dir_name).count + current = 0 + Dir.foreach(dir_name){|file_name| puts file_name; if file_name != '.' && file_name != '..'; - key = Aws::S3::Key.create(bucket, 'uploads/images/' + file_name); - key.put(File.open(dir_name+ '/' + file_name).read, 'public-read'); - key.public_link(); + begin + key = Aws::S3::Key.create(bucket, 'uploads/images/' + file_name); + key.put(File.open(dir_name+ '/' + file_name).read, 'public-read'); + key.public_link(); + puts "Uploaded #{current} of #{count}" + current += 1 + rescue Exception => e + puts "error #{e} on #{current} (#{file_name}), retrying" + retry + end end }