diff --git a/README.md b/README.md index a340a50..2ba5a9d 100644 --- a/README.md +++ b/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 diff --git a/lib/burden/config.rb b/lib/burden/config.rb index ebeed59..da586a8 100644 --- a/lib/burden/config.rb +++ b/lib/burden/config.rb @@ -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 diff --git a/lib/burden/wrapper.rb b/lib/burden/wrapper.rb index 0528c16..4a1cc1b 100644 --- a/lib/burden/wrapper.rb +++ b/lib/burden/wrapper.rb @@ -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