Class: ZSpec::Tracker
- Inherits:
-
Object
- Object
- ZSpec::Tracker
- Defined in:
- lib/zspec/tracker.rb
Instance Attribute Summary collapse
-
#alltime_failures_hash_name ⇒ Object
readonly
Returns the value of attribute alltime_failures_hash_name.
-
#current_failures_hash_name ⇒ Object
readonly
Returns the value of attribute current_failures_hash_name.
-
#runtimes_hash_name ⇒ Object
readonly
Returns the value of attribute runtimes_hash_name.
-
#threshold ⇒ Object
readonly
Returns the value of attribute threshold.
Instance Method Summary collapse
- #all_runtimes ⇒ Object
- #alltime_failures ⇒ Object
- #cleanup(expire_seconds = EXPIRE_SECONDS) ⇒ Object
- #count_key(message) ⇒ Object
- #current_failures ⇒ Object
-
#initialize(build_prefix:, sink:, threshold:, hostname:) ⇒ Tracker
constructor
A new instance of Tracker.
- #sequence_key(message) ⇒ Object
- #time_key(message) ⇒ Object
- #track_failures(failures) ⇒ Object
- #track_runtime(message, runtime) ⇒ Object
- #track_sequence(message) ⇒ Object
Constructor Details
#initialize(build_prefix:, sink:, threshold:, hostname:) ⇒ Tracker
Returns a new instance of Tracker.
5 6 7 8 9 10 11 12 13 |
# File 'lib/zspec/tracker.rb', line 5 def initialize(build_prefix:, sink:, threshold:, hostname:) @sink = sink @threshold = threshold @hostname = hostname @runtimes_hash_name = "runtimes:v1" @alltime_failures_hash_name = "failures:v1" @current_failures_hash_name = build_prefix + ":failures" @sequence_hash_name = build_prefix + ":sequence" end |
Instance Attribute Details
#alltime_failures_hash_name ⇒ Object (readonly)
Returns the value of attribute alltime_failures_hash_name.
3 4 5 |
# File 'lib/zspec/tracker.rb', line 3 def alltime_failures_hash_name @alltime_failures_hash_name end |
#current_failures_hash_name ⇒ Object (readonly)
Returns the value of attribute current_failures_hash_name.
3 4 5 |
# File 'lib/zspec/tracker.rb', line 3 def current_failures_hash_name @current_failures_hash_name end |
#runtimes_hash_name ⇒ Object (readonly)
Returns the value of attribute runtimes_hash_name.
3 4 5 |
# File 'lib/zspec/tracker.rb', line 3 def runtimes_hash_name @runtimes_hash_name end |
#threshold ⇒ Object (readonly)
Returns the value of attribute threshold.
3 4 5 |
# File 'lib/zspec/tracker.rb', line 3 def threshold @threshold end |
Instance Method Details
#all_runtimes ⇒ Object
36 37 38 |
# File 'lib/zspec/tracker.rb', line 36 def all_runtimes @sink.hgetall(@runtimes_hash_name) end |
#alltime_failures ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/zspec/tracker.rb', line 40 def alltime_failures parse_failures( @sink.hgetall(@alltime_failures_hash_name) ) .select(&method(:filter_by_threshold)) .sort_by(&method(:failure_count)) .reverse end |
#cleanup(expire_seconds = EXPIRE_SECONDS) ⇒ Object
57 58 59 60 |
# File 'lib/zspec/tracker.rb', line 57 def cleanup(expire_seconds = EXPIRE_SECONDS) @sink.expire(@current_failures_hash_name, expire_seconds) @sink.expire(@sequence_hash_name, expire_seconds) end |
#count_key(message) ⇒ Object
66 67 68 |
# File 'lib/zspec/tracker.rb', line 66 def count_key() "#{}:count" end |
#current_failures ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/zspec/tracker.rb', line 49 def current_failures parse_failures( @sink.hgetall(@current_failures_hash_name) ) .sort_by(&method(:failure_count)) .reverse end |
#sequence_key(message) ⇒ Object
70 71 72 |
# File 'lib/zspec/tracker.rb', line 70 def sequence_key() "#{}:sequence" end |
#time_key(message) ⇒ Object
62 63 64 |
# File 'lib/zspec/tracker.rb', line 62 def time_key() "#{}:time" end |
#track_failures(failures) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/zspec/tracker.rb', line 25 def track_failures(failures) failures.map { |h| h[:id] }.each do || @sink.hincrby(@alltime_failures_hash_name, count_key(), 1) @sink.hset(@alltime_failures_hash_name, time_key(), @sink.time.first) @sink.hincrby(@current_failures_hash_name, count_key(), 1) @sink.hset(@current_failures_hash_name, time_key(), @sink.time.first) @sink.hset(@current_failures_hash_name, sequence_key(), sequence) end end |
#track_runtime(message, runtime) ⇒ Object
21 22 23 |
# File 'lib/zspec/tracker.rb', line 21 def track_runtime(, runtime) @sink.hset(@runtimes_hash_name, , runtime) end |
#track_sequence(message) ⇒ Object
15 16 17 18 19 |
# File 'lib/zspec/tracker.rb', line 15 def track_sequence() sequence = (@sink.hget(@sequence_hash_name, @hostname) || "").split(",") sequence << @sink.hset(@sequence_hash_name, @hostname, sequence.join(",")) end |