Class: CI::Queue::Redis::BuildRecord
- Inherits:
-
Object
- Object
- CI::Queue::Redis::BuildRecord
- Defined in:
- lib/ci/queue/redis/build_record.rb
Instance Method Summary collapse
- #error_reports ⇒ Object
- #failed_tests ⇒ Object
- #fetch_stats(stat_names) ⇒ Object
-
#initialize(queue, redis, config) ⇒ BuildRecord
constructor
A new instance of BuildRecord.
- #progress ⇒ Object
- #queue_exhausted? ⇒ Boolean
- #record_error(id, payload, stats: nil) ⇒ Object
- #record_success(id, stats: nil) ⇒ Object
- #reset_stats(stat_names) ⇒ Object
Constructor Details
#initialize(queue, redis, config) ⇒ BuildRecord
Returns a new instance of BuildRecord.
5 6 7 8 9 |
# File 'lib/ci/queue/redis/build_record.rb', line 5 def initialize(queue, redis, config) @queue = queue @redis = redis @config = config end |
Instance Method Details
#error_reports ⇒ Object
43 44 45 |
# File 'lib/ci/queue/redis/build_record.rb', line 43 def error_reports redis.hgetall(key('error-reports')) end |
#failed_tests ⇒ Object
19 20 21 |
# File 'lib/ci/queue/redis/build_record.rb', line 19 def failed_tests redis.hkeys(key('error-reports')) end |
#fetch_stats(stat_names) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/ci/queue/redis/build_record.rb', line 47 def fetch_stats(stat_names) counts = redis.pipelined do stat_names.each { |c| redis.hvals(key(c)) } end stat_names.zip(counts.map { |values| values.map(&:to_f).inject(:+).to_f }).to_h end |
#progress ⇒ Object
11 12 13 |
# File 'lib/ci/queue/redis/build_record.rb', line 11 def progress @queue.progress end |
#queue_exhausted? ⇒ Boolean
15 16 17 |
# File 'lib/ci/queue/redis/build_record.rb', line 15 def queue_exhausted? @queue.exhausted? end |
#record_error(id, payload, stats: nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ci/queue/redis/build_record.rb', line 23 def record_error(id, payload, stats: nil) redis.pipelined do redis.hset( key('error-reports'), id.force_encoding(Encoding::BINARY), payload.force_encoding(Encoding::BINARY), ) record_stats(stats) end nil end |
#record_success(id, stats: nil) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/ci/queue/redis/build_record.rb', line 35 def record_success(id, stats: nil) redis.pipelined do redis.hdel(key('error-reports'), id.force_encoding(Encoding::BINARY)) record_stats(stats) end nil end |
#reset_stats(stat_names) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/ci/queue/redis/build_record.rb', line 54 def reset_stats(stat_names) redis.pipelined do stat_names.each do |stat_name| redis.hdel(key(stat_name), config.worker_id) end end end |