Class: MainLoop::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/main_loop/handler.rb

Direct Known Subclasses

ProcessHandler, ThreadHandler

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dispatcherObject (readonly)

Returns the value of attribute dispatcher.



6
7
8
# File 'lib/main_loop/handler.rb', line 6

def dispatcher
  @dispatcher
end

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/main_loop/handler.rb', line 6

def logger
  @logger
end

#nameObject (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:

Returns:

  • (Boolean)


58
59
60
# File 'lib/main_loop/handler.rb', line 58

def finished?
  @finished
end

#handle_retryObject

: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:

Returns:

  • (Boolean)


70
71
72
# File 'lib/main_loop/handler.rb', line 70

def running?
  !finished?
end

#success?Boolean

:nocov:

Returns:

  • (Boolean)


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:

Returns:

  • (Boolean)


76
77
78
# File 'lib/main_loop/handler.rb', line 76

def terminating?
  @terminating_at
end