مراية لـ
https://github.com/postalserver/postal.git
تم المزامنة 2025-12-01 05:43:04 +00:00
callbacks for catching errors on the worker
هذا الالتزام موجود في:
@@ -5,6 +5,7 @@ module Postal
|
||||
def initialize(id, params = {})
|
||||
@id = id
|
||||
@params = params.with_indifferent_access
|
||||
on_initialize
|
||||
end
|
||||
|
||||
def id
|
||||
@@ -15,6 +16,15 @@ module Postal
|
||||
@params || {}
|
||||
end
|
||||
|
||||
def on_initialize
|
||||
# Called whenever the class is initialized. Can be overriden.
|
||||
end
|
||||
|
||||
def on_error(exception)
|
||||
# Called if there's an exception while processing the perform block.
|
||||
# Receives the exception.
|
||||
end
|
||||
|
||||
def perform
|
||||
end
|
||||
|
||||
|
||||
@@ -54,13 +54,14 @@ module Postal
|
||||
klass = message['class_name'].constantize.new(message['id'], message['params'])
|
||||
klass.perform
|
||||
rescue => e
|
||||
if defined?(Raven)
|
||||
Raven.capture_exception(e, :extra => {:job_id => message['id']})
|
||||
end
|
||||
klass.on_error(e) if defined?(klass)
|
||||
logger.warn "[#{message['id']}] \e[31m#{e.class}: #{e.message}\e[0m"
|
||||
e.backtrace.each do |line|
|
||||
logger.warn "[#{message['id']}] " + line
|
||||
end
|
||||
if defined?(Raven)
|
||||
Raven.capture_exception(e, :extra => {:job_id => message['id']})
|
||||
end
|
||||
ensure
|
||||
logger.info "[#{message['id']}] Finished processing \e[34m#{message['class_name']}\e[0m job in #{Time.now - start_time}s"
|
||||
end
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم