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:.
-
#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:
54 55 56 |
# File 'lib/main_loop/handler.rb', line 54 def finished? @finished end |
#handle_retry ⇒ Object
:nocov:
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/main_loop/handler.rb', line 77 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 |
#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:
66 67 68 |
# File 'lib/main_loop/handler.rb', line 66 def running? !finished? end |
#success? ⇒ Boolean
:nocov:
60 61 62 |
# File 'lib/main_loop/handler.rb', line 60 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:
72 73 74 |
# File 'lib/main_loop/handler.rb', line 72 def terminating? @terminating_at end |