lib/right_chimp/exec/Executor.rb in right_chimp-2.1.25.2 vs lib/right_chimp/exec/Executor.rb in right_chimp-2.1.26

- old
+ new

@@ -2,11 +2,11 @@ # Superclass for Executors-- objects that run things on servers # module Chimp class Executor - attr_accessor :server, :array, :exec, :inputs, :template, :owner, :group, + attr_accessor :server, :array, :exec, :inputs, :template, :owner, :group, :delay, :job_id, :job_uuid, :job_notes, :status, :dry_run, :verbose, :quiet, :timeout, :retry_count, :retry_sleep, :time_start, :time_end, :error attr_reader :results @@ -34,10 +34,12 @@ @retry_count = h[:retry_count].to_i || 0 @retry_sleep = h[:retry_sleep].to_i || 30 @timeout = h[:timeout].to_i || 3600 + @delay = h[:delay].to_i || 0 + @error = nil @status = STATUS_NONE @owner = nil @dry_run = false @quiet = false @@ -102,10 +104,18 @@ # Run a unit of work with retries # This is called from the subclass with a code block to yield to # def run_with_retry(&block) Log.debug "Running job '#{@job_id}' with status '#{@status}'" + # If we are not the first job in this group, wait @delay + ChimpDaemon.instance.semaphore.synchronize do + if @group.started >= ChimpQueue.instance.max_threads && @delay.nonzero? + Log.info "[#{@job_uuid}] Sleeping #{@delay} seconds between tasks" + sleep @delay + end + @group.started += 1 + end @status = STATUS_RUNNING @time_start = Time.now Log.info self.describe_work_start unless @quiet @@ -129,10 +139,10 @@ else Log.warn "[#{@job_uuid}][#{@job_id}] Ownership of job_id #{job_id} lost. User cancelled operation?" end rescue SystemExit, Interrupt => ex - $stderr.puts "Exiting!" + $stderr.puts 'Exiting!' raise ex rescue Interrupt => ex name = @array['name'] if @array name = @server['name'] || @server['nickname'] if @server