Callbacks, updated readme
This commit is contained in:
parent
b97f0c1a12
commit
53b0645b8d
29
README.md
29
README.md
@ -1,12 +1,15 @@
|
|||||||
# Burden
|
# 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
|
## Installation
|
||||||
|
|
||||||
Add this line to your application's Gemfile:
|
Add this lines to your application's Gemfile:
|
||||||
```ruby
|
```ruby
|
||||||
gem 'burden'
|
gem 'burden'
|
||||||
|
gem 'burden_web'
|
||||||
```
|
```
|
||||||
|
|
||||||
And then execute:
|
And then execute:
|
||||||
@ -16,18 +19,34 @@ $ bundle
|
|||||||
|
|
||||||
## Configuration
|
## 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
|
```ruby
|
||||||
require 'burden'
|
require 'burden'
|
||||||
|
|
||||||
Burden.configure do |c|
|
Burden.configure do |c|
|
||||||
c.storage = :active_record # or :mongoid, :mongo_mapper
|
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
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
All configuration options are optional.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
stats = Rake::Task['my:task:name'].stats
|
```ruby
|
||||||
stats.log
|
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
|
## Contributing
|
||||||
|
|
||||||
|
@ -1,13 +1,23 @@
|
|||||||
module Burden
|
module Burden
|
||||||
class Config
|
class Config
|
||||||
attr_accessor :storage, # Storage backend (ActiveRecord, Mongoid, MongoMapper)
|
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
|
def initialize
|
||||||
@storage = :active_record
|
@storage = :active_record
|
||||||
@ignored_tasks = [/environment/]
|
@ignored_tasks = [/environment/]
|
||||||
end
|
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
|
module Helper
|
||||||
def config
|
def config
|
||||||
@config ||= Config.new
|
@config ||= Config.new
|
||||||
|
@ -19,7 +19,13 @@ module Burden
|
|||||||
end
|
end
|
||||||
save_statistics
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
Loading…
x
Reference in New Issue
Block a user