Callbacks, updated readme
This commit is contained in:
+12
-2
@@ -1,13 +1,23 @@
|
||||
module Burden
|
||||
class Config
|
||||
attr_accessor :storage, # Storage backend (ActiveRecord, Mongoid, MongoMapper)
|
||||
:ignored_tasks # Do not log this tasks (eg. environment task)
|
||||
attr_accessor :storage, # Storage backend (ActiveRecord, Mongoid, MongoMapper)
|
||||
:ignored_tasks, # Do not log this tasks (eg. environment task)
|
||||
:on_success, # Success callback (expected to be a Proc)
|
||||
:on_failure # Failure callback (expected to be a Proc)
|
||||
|
||||
def initialize
|
||||
@storage = :active_record
|
||||
@ignored_tasks = [/environment/]
|
||||
end
|
||||
|
||||
def trigger_success_callback(name, execution_time)
|
||||
on_success.send(name, execution_time) unless on_success.nil?
|
||||
end
|
||||
|
||||
def trigger_failure_callback(name, execution_time)
|
||||
on_failure.send(name, execution_time) unless on_failure.nil?
|
||||
end
|
||||
|
||||
module Helper
|
||||
def config
|
||||
@config ||= Config.new
|
||||
|
||||
@@ -19,7 +19,13 @@ module Burden
|
||||
end
|
||||
save_statistics
|
||||
|
||||
success ? result : raise(exception)
|
||||
unless success
|
||||
Burden.config.trigger_failure_callback(name, execution_time)
|
||||
raise(exception)
|
||||
end
|
||||
|
||||
Burden.config.trigger_success_callback(name, execution_time)
|
||||
result
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Reference in New Issue
Block a user