Skip to content

Commit

Permalink
another try at fixing the inner loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Apr 14, 2011
1 parent 04c1e84 commit 76c5849
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/cloud_crowd/models/work_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,18 @@ def self.distribute_to_nodes

# Round robin through the nodes and units, sending the unit if the node
# is able to process it.
while (node = available_nodes.shift) && (unit = work_units.shift) do
if node.actions.include?(unit.action)
if node.send_work_unit(unit)
available_nodes.push(node) unless node.busy?
next
work_units.each do |unit|
available_nodes.each do |node|
if node.actions.include? unit.action
if node.send_work_unit unit
work_units.delete unit
available_nodes.delete node if node.busy?
break
end
end
end
work_units.push(unit)
end

# If there are both units and nodes left over, try again.
next if work_units.any? && available_nodes.any?

# If we still have units at this point, or we're fresh out of nodes,
# that means we're done.
return if work_units.any? || available_nodes.empty?
Expand Down

0 comments on commit 76c5849

Please sign in to comment.