Sha256: 31d21ce1d9ae1ed5377d585a8d310e3a612b65c206e0c57d06c6f3b22e487020

Contents?: true

Size: 1.82 KB

Versions: 52

Compression:

Stored size: 1.82 KB

Contents

module Refinery #:nodoc:
  # The statistics class provides a means to record runtime stats
  # about completed jobs and errors. The stats are stored in a SQL
  # database (using SQLite3 by default).
  class Statistics
    include Refinery::Loggable
    
    # Record the done record into the 
    def record_done(message)
      db[:completed_jobs] << {
        :host => message['host_info']['hostname'],
        :pid => message['host_info']['pid'],
        :run_time => message['run_time'],
        :original_message => message['original'],
        :when => Time.now
      }
    end
    
    # Record the error message into the statistics database.
    def record_error(message)
      db[:errors] << {
        :host => message['host_info']['hostname'],
        :pid => message['host_info']['pid'],
        :error_class => message['error']['class'],
        :error_message => message['error']['message'],
        :original_message => message['original'],
        :when => Time.now
      }
    end
    
    private
    # Get a Sequel connection to the stats database
    def db
      @db ||= begin
        db = Sequel.connect('sqlite://stats.db')
        unless db.table_exists?(:completed_jobs)
          db.create_table :completed_jobs do
            primary_key :id
            column :host, :text
            column :pid, :integer
            column :run_time, :float
            column :original_message, :text
            column :when, :time
          end
        end
        unless db.table_exists?(:errors)
          db.create_table :errors do
            primary_key :id
            column :host, :text
            column :pid, :integer
            column :error_class, :text
            column :error_message, :text
            column :original_message, :text
            column :when, :time
          end
        end
        db
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
aeden-refinery-0.10.0 lib/refinery/statistics.rb
aeden-refinery-0.10.1 lib/refinery/statistics.rb
aeden-refinery-0.10.10 lib/refinery/statistics.rb
aeden-refinery-0.10.2 lib/refinery/statistics.rb
aeden-refinery-0.10.3 lib/refinery/statistics.rb
aeden-refinery-0.10.5 lib/refinery/statistics.rb
aeden-refinery-0.10.6 lib/refinery/statistics.rb
aeden-refinery-0.10.8 lib/refinery/statistics.rb
aeden-refinery-0.9.1 lib/refinery/statistics.rb
aeden-refinery-0.9.10 lib/refinery/statistics.rb
aeden-refinery-0.9.11 lib/refinery/statistics.rb
aeden-refinery-0.9.12 lib/refinery/statistics.rb
aeden-refinery-0.9.13 lib/refinery/statistics.rb
aeden-refinery-0.9.14 lib/refinery/statistics.rb
aeden-refinery-0.9.15 lib/refinery/statistics.rb
aeden-refinery-0.9.2 lib/refinery/statistics.rb
aeden-refinery-0.9.4 lib/refinery/statistics.rb
aeden-refinery-0.9.5 lib/refinery/statistics.rb
aeden-refinery-0.9.6 lib/refinery/statistics.rb
aeden-refinery-0.9.7 lib/refinery/statistics.rb