Class: MailHandler::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/mailhandler.rb

Overview

Base handler that does it all

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.begin_work_loopObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/mailhandler.rb', line 7

def self.begin_work_loop
  loop do
    begin
      new.do_work
    rescue StandardError => e
      Logger.error(
        subject: 'Main loop',
        error_type: e.class.to_s,
        trace: e.to_s
      )
      raise e
    end
  end
end

Instance Method Details

#do_workObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mailhandler.rb', line 22

def do_work
  if messages.any?
    messages.each do |message|
      if response = send(email_from(message))
        message.delete unless response.error?
      end
    end
  else
    sleep 1
  end
end