From 66a66e00561afba01cd7fcf99b4b38a8c4dc675c Mon Sep 17 00:00:00 2001 From: Mark Longair Date: Mon, 15 Jul 2013 10:35:22 +0100 Subject: Ignore exceptions when re-extracting attachments This can be a very long-running script, and there is an exception thrown on re-extraction once every 50,000 emails or so. So, just catch any StandardError, output details of the exception and the IncomingMessage ID and then carry on. --- lib/tasks/temp.rake | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'lib/tasks/temp.rake') diff --git a/lib/tasks/temp.rake b/lib/tasks/temp.rake index fcabb23de..ddc3aabd7 100644 --- a/lib/tasks/temp.rake +++ b/lib/tasks/temp.rake @@ -13,15 +13,21 @@ namespace :temp do total_messages = 0 messages_to_reparse = 0 IncomingMessage.find_each :include => :foi_attachments do |im| - reparse = im.foi_attachments.any? { |fa| ! File.exists? fa.filepath } - total_messages += 1 - messages_to_reparse += 1 if reparse - if total_messages % 1000 == 0 - puts "Considered #{total_messages} received emails." - end - unless dry_run - im.parse_raw_email! true if reparse - sleep 2 + begin + reparse = im.foi_attachments.any? { |fa| ! File.exists? fa.filepath } + total_messages += 1 + messages_to_reparse += 1 if reparse + if total_messages % 1000 == 0 + puts "Considered #{total_messages} received emails." + end + unless dry_run + im.parse_raw_email! true if reparse + sleep 2 + end + rescue StandardError => e + puts "There was a #{e.class} exception reparsing IncomingMessage with ID #{im.id}" + puts e.backtrace + puts e.message end end message = dry_run ? "Would reparse" : "Reparsed" -- cgit v1.2.3