Module: Daemon::AllocateWorkers
- Extended by:
- MonitorMixin
- Defined in:
- lib/onapp/engine/allocate_workers.rb
Overview
Encapsulates algorithm for generating array of Daemon::Runner according to available groups
Defined Under Namespace
Classes: WorkerIds
Class Method Summary (collapse)
-
+ (Array<Daemon::Runner>) allocate(max)
Returns Daemon::Runner each with it's own supervisor groups.
Class Method Details
+ (Array<Daemon::Runner>) allocate(max)
Returns Daemon::Runner each with it's own supervisor groups
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/onapp/engine/allocate_workers.rb', line 24 def allocate(max) synchronize do ids = WorkerIds.new workers_left = [max, groups.count].min groups.reduce([]) do |workers, group| if workers_left > 0 workers << Daemon::Runner.new(ids.next) workers_left -= 1 end workers.last.groups << group workers end end end |