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

- old
+ new

@@ -39,10 +39,11 @@ # action in question disabled. def self.distribute_to_nodes reservation = nil filter = {} loop do + WorkUnit.cancel_reservations(reservation) if reservation 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) @@ -67,10 +68,10 @@ # Reserves all available WorkUnits for this process. Returns false if there # were none available. def self.reserve_available(options={}) reservation = ActiveSupport::SecureRandom.random_number(MAX_RESERVATION) - any = WorkUnit.available.update_all("reservation = #{reservation}", nil, options) > 0 + any = WorkUnit.available.update_all("reservation = #{reservation}", options[:conditions], options) > 0 any && reservation end # Cancels all outstanding WorkUnit reservations for this process. def self.cancel_reservations(reservation)