Class: MailRoom::Coordinator

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

Overview

Coordinate the mailbox watchers

Author:

  • Tony Pitale

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mailboxes, health_check = nil) ⇒ Coordinator

build watchers for a set of mailboxes


10
11
12
13
14
15
# File 'lib/mail_room/coordinator.rb', line 10

def initialize(mailboxes, health_check = nil)
  self.watchers = []

  @health_check = health_check
  mailboxes.each {|box| self.watchers << MailboxWatcher.new(box)}
end

Instance Attribute Details

#health_checkObject

Returns the value of attribute health_check.


5
6
7
# File 'lib/mail_room/coordinator.rb', line 5

def health_check
  @health_check
end

#runningObject Also known as: running?

Returns the value of attribute running.


5
6
7
# File 'lib/mail_room/coordinator.rb', line 5

def running
  @running
end

#watchersObject

Returns the value of attribute watchers.


5
6
7
# File 'lib/mail_room/coordinator.rb', line 5

def watchers
  @watchers
end

Instance Method Details

#quitObject

quit each of the watchers when we're done running


32
33
34
35
# File 'lib/mail_room/coordinator.rb', line 32

def quit
  health_check&.quit
  watchers.each(&:quit)
end

#runObject

start each of the watchers to running


20
21
22
23
24
25
26
27
28
29
# File 'lib/mail_room/coordinator.rb', line 20

def run
  health_check&.run
  watchers.each(&:run)

  self.running = true

  sleep_while_running
ensure
  quit
end