lib/belated/job_wrapper.rb in belated-0.7.0 vs lib/belated/job_wrapper.rb in belated-0.8.0
- old
+ new
@@ -11,46 +11,46 @@
# - job retries
# - job retry delay
class JobWrapper
include Comparable
include Logging
- attr_accessor :retries, :max_retries, :id, :job, :at, :completed, :proc_klass, :error, :active_job
+ attr_accessor :retries, :max_retries, :id, :job, :at,
+ :completed, :proc_klass, :error, :active_job
def initialize(job:, max_retries: 5, at: nil, active_job: false)
+ raise 'JobError' unless job.respond_to?(:call) || job.respond_to?(:perform)
+
self.retries = 0
self.max_retries = max_retries
self.id = job.respond_to?(:job_id) ? job.job_id : SecureRandom.uuid
self.job = job
self.at = at
- self.completed = false
self.proc_klass = job.instance_of?(Proc)
self.active_job = active_job
end
def <=>(other)
- at <=> other.at
+ at <=> (other&.at || other&.scheduled_at)
end
# rubocop:disable Lint/RescueException
def perform
resp = execute
self.completed = true
resp
rescue Exception => e
case e.class
- when Interrupt, SignalException
+ when Interrupt, SignalException, NoMethodError
raise e
else
retry_job(e)
"Error while executing job #{job.inspect}, #{e.inspect}. Retry #{retries} of #{max_retries}"
end
end
# rubocop:enable Lint/RescueException
def execute
- if active_job
- ActiveJob::Base.execute job.serialize
- elsif job.respond_to?(:call)
+ if job.respond_to?(:call)
job.call
elsif job.respond_to?(:arguments)
job.perform(*job.arguments)
else
job.perform