lib/backburner/worker.rb in backburner-allq-1.0.18 vs lib/backburner/worker.rb in backburner-allq-1.0.19
- old
+ new
@@ -128,15 +128,17 @@
# @raise [Beaneater::NotConnected] If beanstalk fails to connect multiple times.
def work_one_job(conn = connection)
begin
job = reserve_job(conn)
rescue Exception => e
+ self.log_error "Sleeping"
+ self.log_error "Exception: #{e.full_message}"
sleep(rand*3)
return
end
- if job
+ if job && job.body
begin
self.log_job_begin(job.name, job.args)
job.process
self.log_job_end(job.name)
rescue Backburner::Job::JobFormatInvalid => e
@@ -154,19 +156,24 @@
num_retries = job.releases
max_job_retries = resolve_max_job_retries(job.job_class)
retry_status = "failed: attempt #{num_retries+1} of #{max_job_retries+1}"
retry_delay = resolve_retry_delay(job.job_class)
delay = resolve_retry_delay_proc(job.job_class).call(retry_delay, num_retries) rescue retry_delay
+ puts "num_retries = #{num_retries}"
+ puts "max_job_retries = #{max_job_retries}"
+
if num_retries + 1 > max_job_retries
job.bury
else
job.release(delay)
end
self.log_job_end(job.name, "#{retry_status}, retrying in #{delay}s") if job_started_at
handle_error(e, job.name, job.args, job)
end
+ else
+ sleep(rand*3)
end
job
end
@@ -178,10 +185,10 @@
end
# Reserve a job from the watched queues
def reserve_job(conn, reserve_timeout = Backburner.configuration.reserve_timeout)
job = conn.get(@tube_names.sample)
- return nil if job.body == nil?
+ return nil if job.nil? || job.body == nil?
Backburner::Job.new(job)
end
# Returns a list of all tubes known within the system
# Filtered for tubes that match the known prefix