# Simple library to aid in tracking statistics regarding Kthxbye and its workers. # Submits jobs processed stats, total failures, total uptime, etc. # Puts all stats in stats:x vars in Redis. Super flexible, made to allow tracking # of any kind of count internally # # Built in stats (tracked by Kthxbye internals) include the following # # processed - the count of processed jobs # :processed - the count a given worker has processed # failures - the count of failed jobs module Kthxbye module Stats extend self extend Helper # get count for a given stat (can also use [] method) def get( stat ) redis.get( "stat:#{stat}" ).to_i end alias_method :[], :get # increment a count by a given value (defaults to 1) def incr( stat, by=1 ) redis.incrby("stat:#{stat}", by) end # decrement a count by a given value (defaults to 1) def decr( stat, by=1 ) redis.decrby("stat:#{stat}", by) end # reset this stat to 0 def reset( stat ) redis.del( "stat:#{stat}" ) end end end