Class: Zombees::Swarm
- Inherits:
-
Object
- Object
- Zombees::Swarm
- Extended by:
- Forwardable
- Includes:
- Yell::Loggable
- Defined in:
- lib/zombees/swarm.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#honey_comb ⇒ Object
readonly
Returns the value of attribute honey_comb.
-
#worker_count ⇒ Object
readonly
Returns the value of attribute worker_count.
Instance Method Summary collapse
- #breed ⇒ Object
-
#initialize(options, population = nil) ⇒ Swarm
constructor
A new instance of Swarm.
- #population ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(options, population = nil) ⇒ Swarm
Returns a new instance of Swarm.
13 14 15 16 17 18 |
# File 'lib/zombees/swarm.rb', line 13 def initialize(, population=nil) @worker_count = .worker_count @adapter = .command @honey_comb = .honey_comb @population = population end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
9 10 11 |
# File 'lib/zombees/swarm.rb', line 9 def command @command end |
#honey_comb ⇒ Object (readonly)
Returns the value of attribute honey_comb.
9 10 11 |
# File 'lib/zombees/swarm.rb', line 9 def honey_comb @honey_comb end |
#worker_count ⇒ Object (readonly)
Returns the value of attribute worker_count.
9 10 11 |
# File 'lib/zombees/swarm.rb', line 9 def worker_count @worker_count end |
Instance Method Details
#breed ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/zombees/swarm.rb', line 20 def breed logger.info "Resurrecting the bees population of #{worker_count}" @population ||= worker_count.downto(1).pmap do |index| worker = honey_comb.worker begin logger.info "Bee #{ index } is getting ready to fight" worker.bootstrap.tap { |w| @adapter.prepare(w) } rescue => e logger.error "ARGH! Bee #{ index } stayed dead: #{e.inspect}" worker.shutdown(e) end worker end end |
#population ⇒ Object
36 37 38 |
# File 'lib/zombees/swarm.rb', line 36 def population breed end |
#run ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/zombees/swarm.rb', line 40 def run logger.info "The swarm lurches toward the target..." results = population.pmap do |worker| begin logger.info "A zombie bee is attacking the target!" @adapter.run(worker) rescue => e logger.error "A zombie bee can't reach the brains due to #{e.}" logger.debug e.backtrace ensure logger.info "A zombie bee is full of brains... Going back to the grave" #logger.debug "worker: #{ worker.object_id } server: #{ worker.server.inspect }" worker.shutdown end end logger.info "Digesting acquired brains" @adapter.aggregate(results) end |