Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

another try at fixing the inner loop.

  • Loading branch information...
commit 76c58490fa58d82f2bfc53680d8ba57b30a22706 1 parent 04c1e84
@jashkenas jashkenas authored
Showing with 8 additions and 9 deletions.
  1. +8 −9 lib/cloud_crowd/models/work_unit.rb
View
17 lib/cloud_crowd/models/work_unit.rb
@@ -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?
Please sign in to comment.
Something went wrong with that request. Please try again.