Class: Msgr::Pool::Worker
- Inherits:
-
Object
- Object
- Msgr::Pool::Worker
- Includes:
- Celluloid, Logging
- Defined in:
- lib/msgr/pool.rb
Overview
Worker actor capsuling worker logic and dispatching tasks to custom runner object.
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#pool ⇒ Object
readonly
Returns the value of attribute pool.
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
Instance Method Summary collapse
-
#dispatch(args) ⇒ Object
Dispatch given method and argument to custom runner.
-
#initialize(pool, index, runner_klass, runner_args) ⇒ Worker
constructor
A new instance of Worker.
- #to_s ⇒ Object
Methods included from Logging
Constructor Details
#initialize(pool, index, runner_klass, runner_args) ⇒ Worker
Returns a new instance of Worker.
132 133 134 135 136 137 138 139 |
# File 'lib/msgr/pool.rb', line 132 def initialize(pool, index, runner_klass, runner_args) @pool = pool @poolname = pool.to_s @index = index @runner = runner_klass.new *runner_args log(:debug) { 'Worker ready.' } end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
130 131 132 |
# File 'lib/msgr/pool.rb', line 130 def index @index end |
#pool ⇒ Object (readonly)
Returns the value of attribute pool.
130 131 132 |
# File 'lib/msgr/pool.rb', line 130 def pool @pool end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
130 131 132 |
# File 'lib/msgr/pool.rb', line 130 def runner @runner end |
Instance Method Details
#dispatch(args) ⇒ Object
Dispatch given method and argument to custom runner. Arguments are used to call #send on runner instance.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/msgr/pool.rb', line 144 def dispatch(args) log(:debug) { "Dispatch to runner: #{runner.class.name}" } # Send method to custom runner. runner.send :call, *args rescue => error log(:error) { "Received error from runner: #{error.message}\n#{error.backtrace.join(" \n")}" } ensure if pool.alive? pool.executed Actor.current else terminate end end |
#to_s ⇒ Object
160 161 162 |
# File 'lib/msgr/pool.rb', line 160 def to_s "#{@poolname}[##{index}]" end |