lib/para/job/base.rb in para-0.6.3 vs lib/para/job/base.rb in para-0.6.7
- old
+ new
@@ -1,14 +1,16 @@
module Para
module Job
class Base < ActiveJob::Base
include ActiveJob::Status
- # Used to store import errors on the object
+ # Used to store job errors on the object
include ActiveModel::Validations
- # Used to translate importer name with rails default `activemodel` i18n keys
+ # Used to translate job name with rails default `activemodel` i18n keys
extend ActiveModel::Translation
+ rescue_from Exception, with: :rescue_exception
+
before_perform :store_job_type
protected
def store_job_type
@@ -31,12 +33,12 @@
end
def ensure_total_progress
return if @total_progress
- @total_progress ||= if respond_to?(:progress_total)
- progress.total = progress_total
+ @total_progress ||= if respond_to?(:total_progress, true)
+ progress.total = total_progress
else
progress[:total]
end
end
@@ -44,9 +46,26 @@
if value
status.update(key => value)
else
status[key]
end
+ end
+
+ def rescue_exception(exception)
+ status.update(status: :failed)
+
+ tag_logger(self.class.name, job_id) do
+ ActiveSupport::Notifications.instrument "failed.active_job",
+ adapter: self.class.queue_adapter, job: self, exception: exception
+ end
+
+ if defined?(ExceptionNotifier)
+ ExceptionNotifier.notify_exception(
+ exception, data: { job: self.class.name, payload: arguments }
+ )
+ end
+
+ raise exception
end
end
end
end