14 self.class.i_am_the_instance self
19 if @last_poll.nil? || (Time.now - @last_poll) >= DELAY
20 mbid = BufferManager.say "Polling for new messages..."
21 num, numi = poll { |s| BufferManager.say s, mbid }
22 BufferManager.clear mbid
23 BufferManager.flash "Loaded #{num} new messages, #{numi} to inbox." if num > 0
30 return [0, 0] if @polling
35 Index.usual_sources.each do |source|
37 yield "Loading from #{source}... "
42 source.each do |offset, labels|
43 start_offset ||= offset
46 m = Redwood::Message.new source, offset, labels
48 yield "Skipping duplicate message #{m.id}"
54 if Index.add_message m
55 UpdateManager.relay :add, m
58 total_numi += 1 if m.labels.include? :inbox
60 rescue Redwood::MessageFormatError => e
61 yield "Ignoring erroneous message at #{source}##{offset}: #{e.message}"
64 if num % 1000 == 0 && num > 0
65 elapsed = Time.now - start
66 pctdone = (offset.to_f - start_offset) / (source.total.to_f - start_offset)
67 remaining = (source.total.to_f - offset.to_f) * (elapsed.to_f / (offset.to_f - start_offset))
68 yield "## #{num} (#{(pctdone * 100.0)}% done) read; #{elapsed.to_time_s} elapsed; est. #{remaining.to_time_s} remaining"
71 yield "Found #{num} messages" unless num == 0
73 yield "Done polling; loaded #{total_num} new messages total"
76 [total_num, total_numi]