Class: PerfectQueue::Application::Dispatch
- Defined in:
- lib/perfectqueue/application/dispatch.rb
Instance Attribute Summary collapse
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
Attributes inherited from Runner
Class Method Summary collapse
- .add_route(pattern, klass, options) ⇒ Object
- .route(options) ⇒ Object
- .router ⇒ Object
- .router=(router) ⇒ Object
Instance Method Summary collapse
-
#initialize(task) ⇒ Dispatch
constructor
Runner interface.
- #kill(reason) ⇒ Object
- #run ⇒ Object
Methods inherited from Runner
Constructor Details
#initialize(task) ⇒ Dispatch
Runner interface
24 25 26 27 28 29 30 31 32 |
# File 'lib/perfectqueue/application/dispatch.rb', line 24 def initialize(task) base = self.class.router.route(task.type) unless base task.retry! raise "Unknown task type #{task.type.inspect}" # TODO error class end @runner = base.new(task) super end |
Instance Attribute Details
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
34 35 36 |
# File 'lib/perfectqueue/application/dispatch.rb', line 34 def runner @runner end |
Class Method Details
.add_route(pattern, klass, options) ⇒ Object
55 56 57 |
# File 'lib/perfectqueue/application/dispatch.rb', line 55 def add_route(pattern, klass, ) router.add(pattern, klass, ) end |
.route(options) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/perfectqueue/application/dispatch.rb', line 46 def route() patterns = .keys.select {|k| !k.is_a?(Symbol) } klasses = patterns.map {|k| .delete(k) } patterns.zip(klasses).each {|pattern,sym| add_route(pattern, sym, ) } nil end |
.router ⇒ Object
66 67 68 |
# File 'lib/perfectqueue/application/dispatch.rb', line 66 def router self.router = Router.new end |
.router=(router) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/perfectqueue/application/dispatch.rb', line 59 def router=(router) (class<<self;self;end).instance_eval do self.__send__(:define_method, :router) { router } end router end |
Instance Method Details
#kill(reason) ⇒ Object
40 41 42 |
# File 'lib/perfectqueue/application/dispatch.rb', line 40 def kill(reason) @runner.kill(reason) end |
#run ⇒ Object
36 37 38 |
# File 'lib/perfectqueue/application/dispatch.rb', line 36 def run @runner.run end |