Sha256: 043de118493a1fa1b849d9e5d098c855b4916151137fd4d34494c550c988aeff

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

module Oxidized
  class Node
    class Stats
      MAX_STAT = 10

      # @param [Job] job job whose information add to stats
      # @return [void]
      def add job
        stat = {
          :start  => job.start,
          :end    => job.end,
          :time   => job.time,
        }
        @stats[job.status] ||= []
        @stats[job.status].shift if @stats[job.status].size > MAX_STAT
        @stats[job.status].push stat
        @stats[:counter][job.status] += 1
      end

      # @param [Symbol] status stats for specific status
      # @return [Hash,Array] Hash of stats for every status or Array of stats for specific status
      def get status = nil
        status ? @stats[status] : @stats
      end

      def get_counter counter = nil
        counter ? @stats[:counter][counter] : @stats[:counter]
      end

      def successes
        @stats[:counter][:success]
      end

      def failures
        @stats[:counter].reduce(0) { |m, h| h[0] == :success ? m : m + h[1] }
      end

      private

      def initialize
        @stats = {}
        @stats[:counter] = Hash.new 0
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
oxidized-0.22.0 lib/oxidized/node/stats.rb