Class: MailRoom::MailboxWatcher
- Inherits:
-
Object
- Object
- MailRoom::MailboxWatcher
- Defined in:
- lib/mail_room/mailbox_watcher.rb
Overview
Watch a Mailbox
Instance Attribute Summary collapse
-
#watching_thread ⇒ Object
Returns the value of attribute watching_thread.
Instance Method Summary collapse
-
#initialize(mailbox) ⇒ MailboxWatcher
constructor
Watch a new mailbox.
-
#quit ⇒ Object
stop running, cleanup connection.
-
#run ⇒ Object
run the mailbox watcher.
-
#running? ⇒ Boolean
are we running?.
Constructor Details
#initialize(mailbox) ⇒ MailboxWatcher
Watch a new mailbox
11 12 13 14 15 16 |
# File 'lib/mail_room/mailbox_watcher.rb', line 11 def initialize(mailbox) @mailbox = mailbox @running = false @connection = nil end |
Instance Attribute Details
#watching_thread ⇒ Object
Returns the value of attribute watching_thread.
7 8 9 |
# File 'lib/mail_room/mailbox_watcher.rb', line 7 def watching_thread @watching_thread end |
Instance Method Details
#quit ⇒ Object
stop running, cleanup connection
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mail_room/mailbox_watcher.rb', line 43 def quit @mailbox.logger.info({ context: @mailbox.context, action: "Quitting connection..." }) @running = false if @connection @connection.quit @connection = nil end if self.watching_thread self.watching_thread.join end end |
#run ⇒ Object
run the mailbox watcher
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mail_room/mailbox_watcher.rb', line 25 def run @mailbox.logger.info({ context: @mailbox.context, action: "Setting up watcher" }) @running = true connection. do || @mailbox.deliver() end self.watching_thread = Thread.start do while(running?) do connection.wait end end watching_thread.abort_on_exception = true end |
#running? ⇒ Boolean
are we running?
20 21 22 |
# File 'lib/mail_room/mailbox_watcher.rb', line 20 def running? @running end |