Class: BBK::App::Middlewares::Watchdog

Inherits:
Base
  • Object
show all
Defined in:
lib/bbk/app/middlewares/watchdog.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#app

Instance Method Summary collapse

Constructor Details

#initialize(publisher, route, message_factory, reply_to, delay: 20, timeout: 60, watcher_delay: 40) ⇒ Watchdog

Returns a new instance of Watchdog.



9
10
11
12
13
14
15
16
17
18
# File 'lib/bbk/app/middlewares/watchdog.rb', line 9

def initialize(publisher, route, message_factory, reply_to, delay: 20, timeout: 60, watcher_delay: 40)
  @publisher = publisher
  @route = route
  @message_factory = message_factory
  @reply_to = reply_to
  @delay = delay
  @timeout = timeout
  @timestamp = Time.now.to_i
  @watcher_delay = watcher_delay
end

Instance Attribute Details

#delayObject (readonly)

Returns the value of attribute delay.



6
7
8
# File 'lib/bbk/app/middlewares/watchdog.rb', line 6

def delay
  @delay
end

#message_factoryObject (readonly)

Returns the value of attribute message_factory.



6
7
8
# File 'lib/bbk/app/middlewares/watchdog.rb', line 6

def message_factory
  @message_factory
end

#pinger_threadObject (readonly)

Returns the value of attribute pinger_thread.



6
7
8
# File 'lib/bbk/app/middlewares/watchdog.rb', line 6

def pinger_thread
  @pinger_thread
end

#publisherObject (readonly)

Returns the value of attribute publisher.



6
7
8
# File 'lib/bbk/app/middlewares/watchdog.rb', line 6

def publisher
  @publisher
end

#reply_toObject (readonly)

Returns the value of attribute reply_to.



6
7
8
# File 'lib/bbk/app/middlewares/watchdog.rb', line 6

def reply_to
  @reply_to
end

#routeObject (readonly)

Returns the value of attribute route.



6
7
8
# File 'lib/bbk/app/middlewares/watchdog.rb', line 6

def route
  @route
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



6
7
8
# File 'lib/bbk/app/middlewares/watchdog.rb', line 6

def timeout
  @timeout
end

#watcher_delayObject (readonly)

Returns the value of attribute watcher_delay.



6
7
8
# File 'lib/bbk/app/middlewares/watchdog.rb', line 6

def watcher_delay
  @watcher_delay
end

#watcher_threadObject (readonly)

Returns the value of attribute watcher_thread.



6
7
8
# File 'lib/bbk/app/middlewares/watchdog.rb', line 6

def watcher_thread
  @watcher_thread
end

Instance Method Details

#build(app) ⇒ Object



20
21
22
23
# File 'lib/bbk/app/middlewares/watchdog.rb', line 20

def build(app)
  @app = app
  self
end

#call(msg) ⇒ Object



25
26
27
28
# File 'lib/bbk/app/middlewares/watchdog.rb', line 25

def call(msg)
  touch
  @app.call(msg)
end

#startObject



30
31
32
33
34
35
# File 'lib/bbk/app/middlewares/watchdog.rb', line 30

def start
  touch
  start_ping
  start_watch
  self
end

#stopObject



37
38
39
40
# File 'lib/bbk/app/middlewares/watchdog.rb', line 37

def stop
  @pinger_thread&.kill
  @watcher_thread&.kill
end