Sha256: 831075641bb3df26cfadb2b00a7324aa1f772048ae4cce27c096049a9ac78814

Contents?: true

Size: 842 Bytes

Versions: 24

Compression:

Stored size: 842 Bytes

Contents

require 'securerandom'

module Harness
  class Counter < Measurement
    def self.from_event(event)
      if event.payload[:counter].is_a? Hash
        counter = new event.payload[:counter]
      elsif event.payload[:counter].is_a?(Symbol) || event.payload[:counter].is_a?(String)
        counter = new :id => event.payload[:counter].to_s
      else
        counter = new
      end

      counter.id ||= event.name

      Harness.redis.sadd 'counters', counter.id

      if event.payload[:counter].is_a? Fixnum
        counter.value = event.payload[:counter]
      end

      if counter.value
        Harness.redis.set counter.id, counter.value
      else
        counter.value = Harness.redis.incr(counter.id).to_i
      end

      Harness.redis.zadd "meters/#{counter.id}", counter.time.to_f, counter.value

      counter
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
harness-0.8.1 lib/harness/counter.rb
harness-0.8.0 lib/harness/counter.rb
harness-0.7.0 lib/harness/counter.rb
harness-0.6.0 lib/harness/counter.rb
harness-0.5.0 lib/harness/counter.rb
harness-0.4.0 lib/harness/counter.rb
harness-0.3.0 lib/harness/counter.rb
harness-0.2.16 lib/harness/counter.rb
harness-0.2.15 lib/harness/counter.rb
harness-0.2.14 lib/harness/counter.rb
harness-0.2.13 lib/harness/counter.rb
harness-0.2.12 lib/harness/counter.rb
harness-0.2.11 lib/harness/counter.rb
harness-0.2.10 lib/harness/counter.rb
harness-0.2.9 lib/harness/counter.rb
harness-0.2.8 lib/harness/counter.rb
harness-0.2.7 lib/harness/counter.rb
harness-0.2.6 lib/harness/counter.rb
harness-0.2.5 lib/harness/counter.rb
harness-0.2.4 lib/harness/counter.rb