Class: MainLoop::Handler
- Inherits:
-
Object
- Object
- MainLoop::Handler
- Defined in:
- lib/main_loop/handler.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#dispatcher ⇒ Object
readonly
Returns the value of attribute dispatcher.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#finished? ⇒ Boolean
:nocov:.
-
#handle_retry ⇒ Object
:nocov:.
-
#id(*_args) ⇒ Object
:nocov:.
-
#initialize(dispatcher, name, *_args, retry_count: 0, logger: nil, **_kwargs) ⇒ Handler
constructor
A new instance of Handler.
-
#kill(*_args) ⇒ Object
:nocov:.
-
#on_term(&block) ⇒ Object
:nocov:.
-
#publish(event) ⇒ Object
:nocov:.
-
#reap(*_args) ⇒ Object
:nocov:.
-
#run(*_args) ⇒ Object
:nocov:.
-
#running? ⇒ Boolean
:nocov:.
-
#success? ⇒ Boolean
:nocov:.
-
#term(*_args) ⇒ Object
:nocov:.
-
#terminating? ⇒ Boolean
:nocov:.
Constructor Details
#initialize(dispatcher, name, *_args, retry_count: 0, logger: nil, **_kwargs) ⇒ Handler
Returns a new instance of Handler.
8 9 10 11 12 13 14 15 |
# File 'lib/main_loop/handler.rb', line 8 def initialize(dispatcher, name, *_args, retry_count: 0, logger: nil, **_kwargs) @dispatcher = dispatcher @name = name @code = 0 @retry_count = retry_count @logger = logger || Logger.new(nil) @handler_type = 'Unknown' end |
Instance Attribute Details
#dispatcher ⇒ Object (readonly)
Returns the value of attribute dispatcher.
6 7 8 |
# File 'lib/main_loop/handler.rb', line 6 def dispatcher @dispatcher end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/main_loop/handler.rb', line 6 def logger @logger end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/main_loop/handler.rb', line 6 def name @name end |
Instance Method Details
#finished? ⇒ Boolean
:nocov:
58 59 60 |
# File 'lib/main_loop/handler.rb', line 58 def finished? @finished end |
#handle_retry ⇒ Object
:nocov:
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/main_loop/handler.rb', line 81 def handle_retry if @retry_count == :unlimited logger.info "#{@handler_type}[#{name}] retry...." self.run(&@block) elsif @retry_count && (@retry_count -= 1) >= 0 logger.info "#{@handler_type}[#{name}] retry...." self.run(&@block) else publish(:term) end end |
#id(*_args) ⇒ Object
:nocov:
18 19 20 |
# File 'lib/main_loop/handler.rb', line 18 def id(*_args) raise 'not implemented!' end |
#kill(*_args) ⇒ Object
:nocov:
36 37 38 |
# File 'lib/main_loop/handler.rb', line 36 def kill(*_args) raise 'not implemented!' end |
#on_term(&block) ⇒ Object
:nocov:
53 54 55 |
# File 'lib/main_loop/handler.rb', line 53 def on_term &block @on_term = block end |
#publish(event) ⇒ Object
:nocov:
48 49 50 |
# File 'lib/main_loop/handler.rb', line 48 def publish(event) dispatcher.bus.puts(event) end |
#reap(*_args) ⇒ Object
:nocov:
42 43 44 |
# File 'lib/main_loop/handler.rb', line 42 def reap(*_args) raise 'not implemented!' end |
#run(*_args) ⇒ Object
:nocov:
30 31 32 |
# File 'lib/main_loop/handler.rb', line 30 def run(*_args) raise 'not implemented!' end |
#running? ⇒ Boolean
:nocov:
70 71 72 |
# File 'lib/main_loop/handler.rb', line 70 def running? !finished? end |
#success? ⇒ Boolean
:nocov:
64 65 66 |
# File 'lib/main_loop/handler.rb', line 64 def success? finished? && @success end |
#term(*_args) ⇒ Object
:nocov:
24 25 26 |
# File 'lib/main_loop/handler.rb', line 24 def term(*_args) raise 'not implemented!' end |
#terminating? ⇒ Boolean
:nocov:
76 77 78 |
# File 'lib/main_loop/handler.rb', line 76 def terminating? @terminating_at end |