Callbacks, updated readme
This commit is contained in:
parent
b97f0c1a12
commit
53b0645b8d
29
README.md
29
README.md
@ -1,12 +1,15 @@
|
||||
# Burden
|
||||
|
||||
Burden is a tool for managing Rake tasks.
|
||||
Burden is a task management tool for Rake. It records all tasks invocations.
|
||||
|
||||
Burden Web is a web interface for Burden.
|
||||
|
||||
## Installation
|
||||
|
||||
Add this line to your application's Gemfile:
|
||||
Add this lines to your application's Gemfile:
|
||||
```ruby
|
||||
gem 'burden'
|
||||
gem 'burden_web'
|
||||
```
|
||||
|
||||
And then execute:
|
||||
@ -16,18 +19,34 @@ $ bundle
|
||||
|
||||
## Configuration
|
||||
|
||||
Add this lines to the top of your application's Rakefile:
|
||||
For non-Rails apps, add these lines to the top of your application's Rakefile.
|
||||
|
||||
For Rails apps, create an initializer containing these lines.
|
||||
|
||||
```ruby
|
||||
require 'burden'
|
||||
|
||||
Burden.configure do |c|
|
||||
c.storage = :active_record # or :mongoid, :mongo_mapper
|
||||
c.ignored_tasks = [/^db:/, /environment/]
|
||||
c.on_failure = ->(task_name, execution_time){
|
||||
Mail.new(to: me,
|
||||
subject: "Task #{task_name} failed!",
|
||||
body: "Current time: #{Time.now}\nExecution time: #{execution_time}s"
|
||||
).send
|
||||
}
|
||||
end
|
||||
```
|
||||
|
||||
All configuration options are optional.
|
||||
|
||||
## Usage
|
||||
|
||||
stats = Rake::Task['my:task:name'].stats
|
||||
stats.log
|
||||
```ruby
|
||||
Burden::Storage.run.where(name: 'db:migrate', success: false).order('created_at desc').limit(10)
|
||||
```
|
||||
|
||||
See Burden Web instructions to set up its interface.
|
||||
|
||||
## Contributing
|
||||
|
||||
|
@ -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)
|
||||
: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
|
||||
|
Loading…
x
Reference in New Issue
Block a user