diff options
author | Mark Longair <mhl@pobox.com> | 2013-07-15 10:35:22 +0100 |
---|---|---|
committer | Mark Longair <mhl@pobox.com> | 2013-07-15 10:35:22 +0100 |
commit | 66a66e00561afba01cd7fcf99b4b38a8c4dc675c (patch) | |
tree | 389b3914396f6cb655f80f9215cb5192e5e37f2a | |
parent | d38d747b8cd29df580ad76c8133bb25efb744532 (diff) |
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.
-rw-r--r-- | lib/tasks/temp.rake | 24 |
1 files changed, 15 insertions, 9 deletions
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" |