@@ -8,6 +8,7 @@ BASE_DIR = Rails.root.join('tmp')
88
99params = { }
1010OptionParser . new do |opts |
11+ opts . on ( '--local' )
1112 opts . on ( '--list LIST' )
1213 opts . on ( '--from FROM' , Integer )
1314 opts . on ( '--to TO' , Integer )
@@ -22,17 +23,27 @@ Rails.logger.level = Logger::INFO
2223Message . transaction do
2324 ( params [ :from ] ..params [ :to ] ) . each do |seq |
2425 begin
25- filepath = BASE_DIR . join ( list . name , seq . to_s )
26- next unless filepath . exist?
27-
28- str = File . binread filepath
29- next if str . blank?
30-
31- mail = Mail . read_from_string str
32- message = Message . from_mail mail , list , seq
26+ if params [ :local ]
27+ filepath = BASE_DIR . join ( list . name , seq . to_s )
28+ raise "No #{ seq . to_s } " unless filepath . exist?
29+ next
30+ next unless filepath . exist?
31+
32+ str = File . binread filepath
33+ next if str . blank?
34+
35+ mail = Mail . read_from_string str
36+ message = Message . from_mail mail , list , seq
37+ else
38+ message = Message . from_s3 ( list , seq )
39+ end
40+
41+ p seq if seq % 10 == 0
3342 message . save!
3443 rescue ActiveRecord ::RecordNotUnique
35- STDERR . puts ( "#{ list } :#{ seq } already exists in Postgres" )
44+ STDERR . puts ( "#{ list . name } :#{ seq } already exists in Postgres" )
45+ rescue Aws ::S3 ::Errors ::NoSuchKey
46+ STDERR . puts ( "#{ list . name } :#{ seq } doesn't exist in S3" )
3647 rescue StandardError => e
3748 errors << [ seq , e ]
3849 STDERR . puts ( "failed to import #{ list . name } :#{ seq } : #{ e } " )
0 commit comments