lib/belated/job_wrapper.rb in belated-0.5.5 vs lib/belated/job_wrapper.rb in belated-0.5.6
- old
+ new
@@ -1,32 +1,43 @@
require 'securerandom'
require_relative 'logging'
class Belated
+ # JobWrapper is a wrapper for a job. It is responsible for
+ # - logging
+ # - error handling
+ # - job execution
+ # - job result handling
+ # - job result logging
+ # - job retries
+ # - job retry delay
class JobWrapper
include Comparable
include Logging
- attr_accessor :retries, :max_retries, :id, :job, :at
+ attr_accessor :retries, :max_retries, :id, :job, :at, :completed
def initialize(job:, max_retries: 5, at: nil)
self.retries = 0
self.max_retries = max_retries
self.id = SecureRandom.uuid
self.job = job
self.at = at
+ self.completed = false
end
- def <=>(another)
- at <=> another.at
+ def <=>(other)
+ at <=> other.at
end
# rubocop:disable Lint/RescueException
def perform
- if job.respond_to?(:call)
- job.call
- else
- job.perform
- end
+ resp = if job.respond_to?(:call)
+ job.call
+ else
+ job.perform
+ end
+ self.completed = true
+ resp
rescue Exception => e
case e.class
when Interrupt, SignalException
raise e
else