Class: Dynflow::Executors::Parallel::Pool::JobStorage
- Inherits:
-
Object
- Object
- Dynflow::Executors::Parallel::Pool::JobStorage
- Defined in:
- lib/dynflow/executors/parallel/pool.rb
Instance Method Summary collapse
- #add(work) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ JobStorage
constructor
A new instance of JobStorage.
- #pop ⇒ Object
Constructor Details
#initialize ⇒ JobStorage
Returns a new instance of JobStorage.
32 33 34 35 |
# File 'lib/dynflow/executors/parallel/pool.rb', line 32 def initialize @round_robin = RoundRobin.new @jobs = Hash.new { |h, k| h[k] = [] } end |
Instance Method Details
#add(work) ⇒ Object
37 38 39 40 |
# File 'lib/dynflow/executors/parallel/pool.rb', line 37 def add(work) @round_robin.add work.execution_plan_id unless tracked?(work) @jobs[work.execution_plan_id] << work end |
#empty? ⇒ Boolean
48 49 50 |
# File 'lib/dynflow/executors/parallel/pool.rb', line 48 def empty? @jobs.empty? end |
#pop ⇒ Object
42 43 44 45 46 |
# File 'lib/dynflow/executors/parallel/pool.rb', line 42 def pop return nil if empty? execution_plan_id = @round_robin.next @jobs[execution_plan_id].shift.tap { delete execution_plan_id if @jobs[execution_plan_id].empty? } end |