Class: Breakout::Worker::App
- Inherits:
-
Object
- Object
- Breakout::Worker::App
- Includes:
- API
- Defined in:
- lib/breakout/app.rb
Instance Attribute Summary collapse
-
#socket ⇒ Object
Returns the value of attribute socket.
-
#stop ⇒ Object
Returns the value of attribute stop.
-
#worker_by_route ⇒ Object
Returns the value of attribute worker_by_route.
Instance Method Summary collapse
Methods included from API
#disconnect, #done_work, #send_messages
Instance Attribute Details
#socket ⇒ Object
Returns the value of attribute socket.
6 7 8 |
# File 'lib/breakout/app.rb', line 6 def socket @socket end |
#stop ⇒ Object
Returns the value of attribute stop.
6 7 8 |
# File 'lib/breakout/app.rb', line 6 def stop @stop end |
#worker_by_route ⇒ Object
Returns the value of attribute worker_by_route.
6 7 8 |
# File 'lib/breakout/app.rb', line 6 def worker_by_route @worker_by_route end |
Instance Method Details
#dispatch(data) ⇒ Object
8 9 10 11 12 |
# File 'lib/breakout/app.rb', line 8 def dispatch(data) route, bid, = data.split("\n", 3) raise "#{route}\n#{bid}\n#{}" unless worker = worker_by_route[route] worker.do_work(bid, ) end |
#run(url = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/breakout/app.rb', line 14 def run(url=nil) unless url url = Breakout.worker_url end self.socket = Socket.new(url) self.worker_by_route = Hash.new Worker::WORKERS.each do |klass| worker = klass.new worker.socket = socket worker_by_route[klass.route] = worker end done_work while data = socket.receive() do dispatch(data) if @stop done_work false break end done_work end end |