lib/right_chimp/queue/ExecutionGroup.rb in right_chimp-2.1.25.2 vs lib/right_chimp/queue/ExecutionGroup.rb in right_chimp-2.1.26

- old
+ new

@@ -20,21 +20,22 @@ # # Only the subclasses SerialExecutionGroup and ParallelExecutionGroup # should be used directly. # class ExecutionGroup - attr_accessor :group_id, :description, :concurrency + attr_accessor :group_id, :description, :concurrency, :started attr_reader :time_start, :time_end def initialize(new_group_id=nil) @group_id = new_group_id @queue = [] @jobs_by_id = {} @log = nil @time_start = nil @time_end = nil @concurrency = 1 + @started = 0 end # # Add something to the work queue # @@ -269,14 +270,19 @@ # # SerialExecutionGroup: run only one job at a time # class SerialExecutionGroup < ExecutionGroup def ready? - return get_jobs_by_status(Executor::STATUS_RUNNING).size == 0 && get_jobs_by_status(Executor::STATUS_NONE).size > 0 + # Make sure only one thread makes the ready question at the same time, + # otherwise we can run into race conditions. This is critical for SerialExecutionGroup + ChimpDaemon.instance.semaphore.synchronize do + ready = get_jobs_by_status(Executor::STATUS_RUNNING).size == 0 && get_jobs_by_status(Executor::STATUS_NONE).size > 0 + return ready + end end def short_name - "S" + 'S' end end # # ParallelExecutionGroup: run multiple jobs at once