aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Longair <mark@mysociety.org>2013-06-10 13:42:10 +0100
committerUser for alaveteli upgrade vhost <foi-upgrade@firefly.ukcod.org.uk>2013-06-11 15:57:44 +0100
commit0d850f8dbd581ea12497e6d34f8e7dc100912982 (patch)
tree83a727680eba7e55a21b5dd0ecfed31b5400e440
parent17d8e8666fa0fd312377b1539348ef4e17f6d161 (diff)
Add a rake task to re-extract any missing attachmentsreextract-attachments
You can see the number of emails that would be reparsed by doing: bundle exec rake temp:reextract_missing_attachments To actually reparse the incoming emails and rextract attachments for any that were missing, you would do: bundle exec rake temp:reextract_missing_attachments[commit] (In fact, the 'commit' can be any non-empty string.)
-rw-r--r--lib/tasks/temp.rake22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/tasks/temp.rake b/lib/tasks/temp.rake
index fd0dd069f..9eda530fd 100644
--- a/lib/tasks/temp.rake
+++ b/lib/tasks/temp.rake
@@ -21,6 +21,28 @@ namespace :temp do
end
end
+ desc "Re-extract any missing cached attachments"
+ task :reextract_missing_attachments, [:commit] => :environment do |t, args|
+ dry_run = args.commit.nil? || args.commit.empty?
+ 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
+ end
+ end
+ message = dry_run ? "Would reparse" : "Reparsed"
+ message += " #{messages_to_reparse} out of #{total_messages} received emails."
+ puts message
+ end
+
desc 'Remove file caches for requests that are not publicly visible or have been destroyed'
task :remove_obsolete_info_request_caches => :environment do
dryrun = ENV['DRYRUN'] == '0' ? false : true