lib/cloud_crowd/models/work_unit.rb in cloud-crowd-0.4.1 vs lib/cloud_crowd/models/work_unit.rb in cloud-crowd-0.5.0

- old
+ new

@@ -37,12 +37,13 @@ # WorkUnits get removed from the availability list when they are # successfully sent, and Nodes get removed when they are busy or have the # action in question disabled. def self.distribute_to_nodes reservation = nil + filter = {} loop do - return unless reservation = WorkUnit.reserve_available(:limit => RESERVATION_LIMIT) + return unless reservation = WorkUnit.reserve_available(:limit => RESERVATION_LIMIT, :conditions => filter) work_units = WorkUnit.reserved(reservation) available_nodes = NodeRecord.available while node = available_nodes.shift and unit = work_units.shift do if node.actions.include?(unit.action) if node.send_work_unit(unit) @@ -51,9 +52,13 @@ end else unit.cancel_reservation end work_units.push(unit) + end + if work_units.any? && available_nodes.any? + filter = {:action => available_nodes.map {|node| node.actions }.flatten.uniq } + next end return if work_units.any? || available_nodes.empty? end ensure WorkUnit.cancel_reservations(reservation) if reservation