Skip to content
Snippets Groups Projects
Commit 9f4568e8 authored by Adam Cooke's avatar Adam Cooke
Browse files

callbacks for catching errors on the worker

parent 97f95fe8
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -5,6 +5,7 @@ module Postal
def initialize(id, params = {})
@id = id
@params = params.with_indifferent_access
on_initialize
end
 
def id
Loading
Loading
@@ -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
 
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment