Timestamp in UTC, abstract storage
This commit is contained in:
parent
861c12aa32
commit
c6f0f2480d
@ -29,10 +29,14 @@ 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.ignored_tasks = [/^db:/, /environment/]
|
||||||
c.on_failure = ->(task_name, execution_time){
|
c.on_failure = ->(task_name, execution_time, timestamp){
|
||||||
Mail.new(to: me,
|
Mail.new(to: me,
|
||||||
subject: "Task #{task_name} failed!",
|
subject: "Task #{task_name} failed!",
|
||||||
body: "Current time: #{Time.now}\nExecution time: #{execution_time}s"
|
body: <<-MSG
|
||||||
|
Started at: #{timestamp}
|
||||||
|
Execution time: #{execution_time}s
|
||||||
|
Status: FAILED
|
||||||
|
MSG
|
||||||
).send
|
).send
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module BurdenWeb
|
module BurdenWeb
|
||||||
class RunsController < ApplicationController
|
class RunsController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@runs = Burden::Storage.run.where(name: params[:task_id]).order('created_at desc').limit(100)
|
@runs = Burden::Storage.run.history(params[:task_id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
<% @runs.each do |run| %>
|
<% @runs.each do |run| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><span class="<%= task_label(run) %> radius label"><%= run.name %></span></td>
|
<td><span class="<%= task_label(run) %> radius label"><%= run.name %></span></td>
|
||||||
<td><%= l run.created_at, format: :short %> (<%= time_ago_in_words(run.created_at) %> ago)</td>
|
<td><%= l run.timestamp, format: :short %> (<%= time_ago_in_words(run.timestamp) %> ago)</td>
|
||||||
<td><%= run.execution_time.round(6) %>s</td>
|
<td><%= run.execution_time.round(6) %>s</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
<% @tasks.each do |run| %>
|
<% @tasks.each do |run| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><span class="<%= task_label(run) %> radius label"><%= run.name %></span></td>
|
<td><span class="<%= task_label(run) %> radius label"><%= run.name %></span></td>
|
||||||
<% if run.created_at %>
|
<% if run.timestamp %>
|
||||||
<td><%= time_ago_in_words(run.created_at) %> ago</td>
|
<td><%= time_ago_in_words(run.timestamp) %> ago</td>
|
||||||
<td><%= run.execution_time.round(6) %>s</td>
|
<td><%= run.execution_time.round(6) %>s</td>
|
||||||
<td><%= link_to 'Run', run_task_path(run.name, back: tasks_path), class: 'small radius button' %></td>
|
<td><%= link_to 'Run', run_task_path(run.name, back: tasks_path), class: 'small radius button' %></td>
|
||||||
<td><%= link_to 'History', task_runs_path(run.name), class: 'secondary small radius button' %></td>
|
<td><%= link_to 'History', task_runs_path(run.name), class: 'secondary small radius button' %></td>
|
||||||
|
@ -4,7 +4,7 @@ class CreateBurdenRuns < ActiveRecord::Migration
|
|||||||
t.string :name
|
t.string :name
|
||||||
t.boolean :success
|
t.boolean :success
|
||||||
t.float :execution_time
|
t.float :execution_time
|
||||||
t.timestamps
|
t.datetime :timestamp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -11,14 +11,13 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20130607070108) do
|
ActiveRecord::Schema.define(:version => 20130607082646) do
|
||||||
|
|
||||||
create_table "burden_runs", :force => true do |t|
|
create_table "burden_runs", :force => true do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.boolean "success"
|
t.boolean "success"
|
||||||
t.float "execution_time"
|
t.float "execution_time"
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "timestamp"
|
||||||
t.datetime "updated_at", :null => false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -10,12 +10,12 @@ module Burden
|
|||||||
@ignored_tasks = [/environment/]
|
@ignored_tasks = [/environment/]
|
||||||
end
|
end
|
||||||
|
|
||||||
def trigger_success_callback(name, execution_time)
|
def trigger_success_callback(name, execution_time, timestamp)
|
||||||
on_success.send(name, execution_time) unless on_success.nil?
|
on_success.send(name, execution_time, timestamp) unless on_success.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def trigger_failure_callback(name, execution_time)
|
def trigger_failure_callback(name, execution_time, timestamp)
|
||||||
on_failure.send(name, execution_time) unless on_failure.nil?
|
on_failure.send(name, execution_time, timestamp) unless on_failure.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
module Helper
|
module Helper
|
||||||
|
@ -1,25 +1,41 @@
|
|||||||
module Burden
|
module Burden
|
||||||
class Statistics
|
class Statistics
|
||||||
attr_reader :name, :success, :execution_time
|
attr_reader :name, :success, :execution_time, :timestamp
|
||||||
|
|
||||||
def initialize(params)
|
def initialize(params)
|
||||||
@name = params[:name]
|
@name = params[:name]
|
||||||
@success = params[:success]
|
@success = params[:success]
|
||||||
@execution_time = params[:execution_time]
|
@execution_time = params[:execution_time]
|
||||||
|
@timestamp = params[:timestamp]
|
||||||
end
|
end
|
||||||
|
|
||||||
def save
|
def save
|
||||||
if defined?(Rails) && Rails.respond_to?(:application) && Rails.application.present?
|
if defined?(Rails) && Rails.respond_to?(:application) && Rails.application.present?
|
||||||
|
# FIXME: Dirty stuff
|
||||||
conf = Rails.configuration.database_configuration[Rails.env]
|
conf = Rails.configuration.database_configuration[Rails.env]
|
||||||
ActiveRecord::Base.establish_connection(conf)
|
ActiveRecord::Base.establish_connection(conf)
|
||||||
Storage.run.create(name: name, success: success, execution_time: execution_time)
|
|
||||||
|
begin
|
||||||
|
Storage.run.create(name: name, success: success, execution_time: execution_time, timestamp: timestamp)
|
||||||
|
rescue
|
||||||
|
log_to_stdout(:failed)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
puts
|
log_to_stdout(:no_rails)
|
||||||
puts "------------------------------------------------------------"
|
|
||||||
puts "Rails environment is not loaded. Sending output to STDOUT"
|
|
||||||
puts "Task #{name} #{success ? 'finished successfully' : 'failed'}"
|
|
||||||
puts "Execution time: #{execution_time.round(4)}"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def log_to_stdout(reason = :no_rails)
|
||||||
|
puts
|
||||||
|
puts "------------------------------------------------------------"
|
||||||
|
case reason
|
||||||
|
when :no_rails
|
||||||
|
puts "Rails environment is not loaded. Sending output to STDOUT"
|
||||||
|
when :failed
|
||||||
|
puts "Failed to persist this run. Sending output to STDOUT"
|
||||||
|
end
|
||||||
|
puts "Task #{name} #{success ? 'finished successfully' : 'failed'}"
|
||||||
|
puts "Execution time: #{execution_time.round(4)}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
28
lib/burden/storage/abstract/run.rb
Normal file
28
lib/burden/storage/abstract/run.rb
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
module Burden
|
||||||
|
module Storage
|
||||||
|
module Abstract
|
||||||
|
class Run
|
||||||
|
attr_accessor :name, :success, :execution_time, :timestamp
|
||||||
|
|
||||||
|
def initialize(attributes = {})
|
||||||
|
@name = attributes[:name]
|
||||||
|
@success = attributes[:success]
|
||||||
|
@execution_time = attributes[:execution_time]
|
||||||
|
@timestamp = attributes[:timestamp]
|
||||||
|
end
|
||||||
|
|
||||||
|
def save
|
||||||
|
raise NotImplementedError.new('Method #save must be overwritten')
|
||||||
|
end
|
||||||
|
|
||||||
|
def summary
|
||||||
|
raise NotImplementedError.new('Method #summary must be overwritten')
|
||||||
|
end
|
||||||
|
|
||||||
|
def history(task_name)
|
||||||
|
raise NotImplementedError.new('Method #history must be overwritten')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -3,9 +3,10 @@ module Burden
|
|||||||
module ActiveRecord
|
module ActiveRecord
|
||||||
class Run < ::ActiveRecord::Base
|
class Run < ::ActiveRecord::Base
|
||||||
self.table_name = 'burden_runs'
|
self.table_name = 'burden_runs'
|
||||||
attr_accessible :name, :success, :execution_time
|
attr_accessible :name, :success, :execution_time, :timestamp
|
||||||
|
|
||||||
scope :summary, ->{ order('created_at desc').group(:name) }
|
scope :summary, ->{ order('timestamp desc').group(:name) }
|
||||||
|
scope :history, ->(task_name){ where(name: task_name).order('timestamp desc').limit(100) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,8 +8,10 @@ module Burden
|
|||||||
key :name, String
|
key :name, String
|
||||||
key :success, Boolean
|
key :success, Boolean
|
||||||
key :execution_time, Float
|
key :execution_time, Float
|
||||||
|
key :timestamp, Time
|
||||||
|
|
||||||
scope :summary, ->{ sort(:created_at.desc).group_by(&:name) }
|
scope :summary, ->{ sort(:timestamp.desc).group_by(&:name) }
|
||||||
|
scope :history, ->(task_name){ where(name: task_name).sort(:timestamp.desc).group_by(&:name) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,8 +8,10 @@ module Burden
|
|||||||
field :name, type: String
|
field :name, type: String
|
||||||
field :success, type: Boolean
|
field :success, type: Boolean
|
||||||
field :execution_time, type: Float
|
field :execution_time, type: Float
|
||||||
|
field :timestamp, type: Time
|
||||||
|
|
||||||
scope :summary, ->{ sort(created_at: -1).group_by(&:name) }
|
scope :summary, ->{ sort(timestamp: -1).group_by(&:name) }
|
||||||
|
scope :history, ->(task_name){ where(name: task_name).sort(timestamp: -1).group_by(&:name) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
module Burden
|
module Burden
|
||||||
class Wrapper
|
class Wrapper
|
||||||
attr_reader :name, :description, :block, :success, :exception, :execution_time
|
attr_reader :name, :block, :success, :exception, :execution_time, :timestamp
|
||||||
|
|
||||||
def initialize(name, description, block)
|
def initialize(name, block)
|
||||||
@name = name
|
@name = name
|
||||||
@description = description
|
|
||||||
@block = block
|
@block = block
|
||||||
@success = true
|
@success = true
|
||||||
|
@timestamp = Time.now.utc
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
@ -20,11 +20,11 @@ module Burden
|
|||||||
save_statistics
|
save_statistics
|
||||||
|
|
||||||
unless success
|
unless success
|
||||||
Burden.config.trigger_failure_callback(name, execution_time)
|
Burden.config.trigger_failure_callback(name, execution_time, timestamp)
|
||||||
raise(exception)
|
raise(exception)
|
||||||
end
|
end
|
||||||
|
|
||||||
Burden.config.trigger_success_callback(name, execution_time)
|
Burden.config.trigger_success_callback(name, execution_time, timestamp)
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ module Burden
|
|||||||
end
|
end
|
||||||
|
|
||||||
def save_statistics
|
def save_statistics
|
||||||
Statistics.new(name: name, success: success, execution_time: execution_time).save
|
Statistics.new(name: name, success: success, execution_time: execution_time, timestamp: timestamp).save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -4,7 +4,7 @@ class CreateBurdenRuns < ActiveRecord::Migration
|
|||||||
t.string :name
|
t.string :name
|
||||||
t.boolean :success
|
t.boolean :success
|
||||||
t.float :execution_time
|
t.float :execution_time
|
||||||
t.timestamps
|
t.datetime :timestamp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user