lib/cloud_crowd/models/work_unit.rb in cloud-crowd-0.7.2.pre3 vs lib/cloud_crowd/models/work_unit.rb in cloud-crowd-0.7.2
- old
+ new
@@ -42,9 +42,12 @@
# Find the available nodes, and determine what actions we're capable
# of running at the moment.
available_nodes = NodeRecord.available.to_a
available_actions = available_nodes.map {|node| node.actions }.flatten.uniq
filter = "action in (#{available_actions.map{|a| "'#{a}'"}.join(',')})"
+
+ # If there aren't any available nodes or actions don't bother doing anything.
+ return if available_nodes.empty? or available_actions.empty?
# Reserve a handful of available work units.
WorkUnit.cancel_reservations(reservation) if reservation
return unless reservation = WorkUnit.reserve_available(:limit => RESERVATION_LIMIT, :conditions => filter)
work_units = WorkUnit.reserved(reservation).to_a