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
13 14 15 16 17 18 |
# File 'lib/mail_room/mailbox_watcher.rb', line 13 def initialize(mailbox) @mailbox = mailbox @running = false @connection = nil end |
Instance Attribute Details
#watching_thread ⇒ Object
Returns the value of attribute watching_thread.
9 10 11 |
# File 'lib/mail_room/mailbox_watcher.rb', line 9 def watching_thread @watching_thread end |
Instance Method Details
#quit ⇒ Object
stop running, cleanup connection
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mail_room/mailbox_watcher.rb', line 45 def quit @mailbox.logger.info({ context: @mailbox.context, action: "Quitting connection..." }) @running = false if @connection @connection.quit @connection = nil end @mailbox.logger.info({ context: @mailbox.context, action: "Terminating watching thread..." }) if self.watching_thread thr = self.watching_thread.join(60) @mailbox.logger.info({ context: @mailbox.context, action: "Timeout waiting for watching thread" }) unless thr end @mailbox.logger.info({ context: @mailbox.context, action: "Done with thread cleanup" }) end |
#run ⇒ Object
run the mailbox watcher
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mail_room/mailbox_watcher.rb', line 27 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?
22 23 24 |
# File 'lib/mail_room/mailbox_watcher.rb', line 22 def running? @running end |