lib/sup/poll.rb in sup-0.9.1 vs lib/sup/poll.rb in sup-0.10

- old
+ new

@@ -26,23 +26,22 @@ from_and_subj: an array of (from email address, subject) pairs from_and_subj_inbox: an array of (from email address, subject) pairs for only those messages appearing in the inbox EOS - DELAY = 300 + DELAY = $config[:poll_interval] || 300 def initialize @mutex = Mutex.new @thread = nil @last_poll = nil @polling = false + @poll_sources = nil @mode = nil end - def poll - return if @polling - @polling = true + def poll_with_sources @mode ||= PollMode.new HookManager.run "before-poll" BufferManager.flash "Polling for new messages..." num, numi, from_and_subj, from_and_subj_inbox, loaded_labels = @mode.poll @@ -52,14 +51,30 @@ BufferManager.flash "No new messages." end HookManager.run "after-poll", :num => num, :num_inbox => numi, :from_and_subj => from_and_subj, :from_and_subj_inbox => from_and_subj_inbox, :num_inbox_total_unread => lambda { Index.num_results_for :labels => [:inbox, :unread] } + end + + def poll + return if @polling + @polling = true + @poll_sources = SourceManager.usual_sources + num, numi = poll_with_sources @polling = false [num, numi] end + def poll_unusual + return if @polling + @polling = true + @poll_sources = SourceManager.unusual_sources + num, numi = poll_with_sources + @polling = false + [num, numi] + end + def start @thread = Redwood::reporting_thread("periodic poll") do while true sleep DELAY / 2 poll if @last_poll.nil? || (Time.now - @last_poll) >= DELAY @@ -77,10 +92,10 @@ from_and_subj = [] from_and_subj_inbox = [] loaded_labels = Set.new @mutex.synchronize do - SourceManager.usual_sources.each do |source| + @poll_sources.each do |source| # yield "source #{source} is done? #{source.done?} (cur_offset #{source.cur_offset} >= #{source.end_offset})" begin yield "Loading from #{source}... " unless source.done? || (source.respond_to?(:has_errors?) && source.has_errors?) rescue SourceError => e warn "problem getting messages from #{source}: #{e.message}"