lib/rest-ftp-daemon/workers/transfer.rb in rest-ftp-daemon-0.424.0 vs lib/rest-ftp-daemon/workers/transfer.rb in rest-ftp-daemon-0.424.2
- old
+ new
@@ -33,41 +33,18 @@
# Wait for a job to be available in the queue
worker_status WORKER_STATUS_WAITING
job = RestFtpDaemon::JobQueue.instance.pop @pool
# Work on this job
- work_on_job(job)
+ work_on_job job
# Clean job status
job.wid = nil
#sleep 1
- # If job status requires a retry, just restack it
- if !job.error
- #log_info "job succeeded"
-
- elsif !(@config[:retry_on].is_a?(Enumerable) && @config[:retry_on].include?(job.error))
- log_error "not retrying: error not eligible"
-
- elsif @config[:retry_for] && (job.age >= @config[:retry_for])
- log_error "not retrying: max_age reached (#{@config[:retry_for]} s)"
-
- elsif @config[:retry_max] && (job.runs >= @config[:retry_max])
- log_error "not retrying: max_runs reached (#{@config[:retry_max]} tries)"
-
- else
- # Delay cannot be negative, and will be 1s minimum
- retry_after = [@config[:retry_after] || DEFAULT_RETRY_AFTER, 1].max
- log_info "retrying job: waiting for #{retry_after} seconds"
-
- # Wait !
- sleep retry_after
- log_info "retrying job: requeued after delay"
-
- # Now, requeue this job
- RestFtpDaemon::JobQueue.instance.requeue job
- end
+ # Handle the retry if needed
+ handle_job_result job
end
def work_on_job job
# Prepare job and worker for processing
worker_jid job.id
@@ -90,29 +67,43 @@
worker_status WORKER_STATUS_TIMEOUT
# Inform the job
job.oops_you_stop_now ex unless job.nil?
- rescue RestFtpDaemon::AttributeMissing => ex
- log_error "JOB MISSING ATTRIBUTE", ex.backtrace
+ rescue RestFtpDaemon::AssertionFailed, RestFtpDaemon::AttributeMissing, StandardError => ex
+ log_error "JOB EXCEPTION ex[#{ex.class}] #{ex.message}", ex.backtrace
worker_status WORKER_STATUS_CRASHED
# Inform the job
- job.oops_you_stop_now ex unless job.nil?
+ job.oops_after_crash ex unless job.nil?
+ end
- rescue RestFtpDaemon::AssertionFailed => ex
- log_error "JOB ASSERTION FAILED", ex.backtrace
- worker_status WORKER_STATUS_CRASHED
+ def handle_job_result job
+ # If job status requires a retry, just restack it
+ if !job.error
+ #log_info "job succeeded"
- # Inform the job
- job.oops_you_stop_now ex unless job.nil?
+ elsif !(@config[:retry_on].is_a?(Enumerable) && @config[:retry_on].include?(job.error))
+ log_error "not retrying: error not eligible"
- rescue StandardError => ex
- log_error "JOB UNHANDLED EXCEPTION ex[#{ex.class}] #{ex.message}", ex.backtrace
- worker_status WORKER_STATUS_CRASHED
+ elsif @config[:retry_for] && (job.age >= @config[:retry_for])
+ log_error "not retrying: max_age reached (#{@config[:retry_for]} s)"
- # Inform the job
- job.oops_after_crash ex unless job.nil?
+ elsif @config[:retry_max] && (job.runs >= @config[:retry_max])
+ log_error "not retrying: max_runs reached (#{@config[:retry_max]} tries)"
+
+ else
+ # Delay cannot be negative, and will be 1s minimum
+ retry_after = [@config[:retry_after] || DEFAULT_RETRY_AFTER, 1].max
+ log_info "retrying job: waiting for #{retry_after} seconds"
+
+ # Wait !
+ sleep retry_after
+ log_info "retrying job: requeued after delay"
+
+ # Now, requeue this job
+ RestFtpDaemon::JobQueue.instance.requeue job
+ end
end
end
end