Class: CI::Queue::Redis::BuildRecord
- Inherits:
-
Object
- Object
- CI::Queue::Redis::BuildRecord
- Defined in:
- lib/ci/queue/redis/build_record.rb
Constant Summary collapse
- TOTAL_KEY =
"___total___"
Instance Method Summary collapse
- #error_reports ⇒ Object
- #failed_tests ⇒ Object
- #fetch_stats(stat_names) ⇒ Object
- #flaky_reports ⇒ Object
-
#initialize(queue, redis, config) ⇒ BuildRecord
constructor
A new instance of BuildRecord.
- #max_test_failed? ⇒ Boolean
- #pop_warnings ⇒ Object
- #progress ⇒ Object
- #queue_exhausted? ⇒ Boolean
- #record_error(id, payload, stats: nil) ⇒ Object
- #record_flaky(id, stats: nil) ⇒ Object
- #record_success(id, stats: nil, skip_flaky_record: false) ⇒ Object
- #record_warning(type, attributes) ⇒ Object
- #report_worker_error(error) ⇒ Object
- #requeued_tests ⇒ Object
- #reset_stats(stat_names) ⇒ Object
- #reset_worker_error ⇒ Object
- #worker_errors ⇒ Object
Constructor Details
#initialize(queue, redis, config) ⇒ BuildRecord
Returns a new instance of BuildRecord.
6 7 8 9 10 |
# File 'lib/ci/queue/redis/build_record.rb', line 6 def initialize(queue, redis, config) @queue = queue @redis = redis @config = config end |
Instance Method Details
#error_reports ⇒ Object
99 100 101 |
# File 'lib/ci/queue/redis/build_record.rb', line 99 def error_reports redis.hgetall(key('error-reports')) end |
#failed_tests ⇒ Object
35 36 37 |
# File 'lib/ci/queue/redis/build_record.rb', line 35 def failed_tests redis.hkeys(key('error-reports')) end |
#fetch_stats(stat_names) ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/ci/queue/redis/build_record.rb', line 107 def fetch_stats(stat_names) counts = redis.pipelined do |pipeline| stat_names.each { |c| pipeline.hvals(key(c)) } end sum_counts = counts.map do |values| values.map(&:to_f).inject(:+).to_f end stat_names.zip(sum_counts).to_h end |
#flaky_reports ⇒ Object
103 104 105 |
# File 'lib/ci/queue/redis/build_record.rb', line 103 def flaky_reports redis.smembers(key('flaky-reports')) end |
#max_test_failed? ⇒ Boolean
93 94 95 96 97 |
# File 'lib/ci/queue/redis/build_record.rb', line 93 def max_test_failed? return false if config.max_test_failed.nil? @queue.test_failures >= config.max_test_failed end |
#pop_warnings ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/ci/queue/redis/build_record.rb', line 46 def pop_warnings warnings = redis.multi do |transaction| transaction.lrange(key('warnings'), 0, -1) transaction.del(key('warnings')) end.first warnings.map { |p| Marshal.load(p) } end |
#progress ⇒ Object
12 13 14 |
# File 'lib/ci/queue/redis/build_record.rb', line 12 def progress @queue.progress end |
#queue_exhausted? ⇒ Boolean
16 17 18 |
# File 'lib/ci/queue/redis/build_record.rb', line 16 def queue_exhausted? @queue.exhausted? end |
#record_error(id, payload, stats: nil) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ci/queue/redis/build_record.rb', line 59 def record_error(id, payload, stats: nil) redis.pipelined do |pipeline| pipeline.hset( key('error-reports'), id.dup.force_encoding(Encoding::BINARY), payload.dup.force_encoding(Encoding::BINARY), ) pipeline.expire(key('error-reports'), config.redis_ttl) record_stats(stats, pipeline: pipeline) end nil end |
#record_flaky(id, stats: nil) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ci/queue/redis/build_record.rb', line 82 def record_flaky(id, stats: nil) redis.pipelined do |pipeline| pipeline.sadd?( key('flaky-reports'), id.b ) pipeline.expire(key('flaky-reports'), config.redis_ttl) end nil end |
#record_success(id, stats: nil, skip_flaky_record: false) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/ci/queue/redis/build_record.rb', line 72 def record_success(id, stats: nil, skip_flaky_record: false) error_reports_deleted_count, requeued_count, _ = redis.pipelined do |pipeline| pipeline.hdel(key('error-reports'), id.dup.force_encoding(Encoding::BINARY)) pipeline.hget(key('requeues-count'), id.b) record_stats(stats, pipeline: pipeline) end record_flaky(id) if !skip_flaky_record && (error_reports_deleted_count.to_i > 0 || requeued_count.to_i > 0) nil end |
#record_warning(type, attributes) ⇒ Object
55 56 57 |
# File 'lib/ci/queue/redis/build_record.rb', line 55 def record_warning(type, attributes) redis.rpush(key('warnings'), Marshal.dump([type, attributes])) end |
#report_worker_error(error) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/ci/queue/redis/build_record.rb', line 20 def report_worker_error(error) redis.pipelined do |pipeline| pipeline.hset(key('worker-errors'), config.worker_id, error.) pipeline.expire(key('worker-errors'), config.redis_ttl) end end |
#requeued_tests ⇒ Object
40 41 42 43 44 |
# File 'lib/ci/queue/redis/build_record.rb', line 40 def requeued_tests requeues = redis.hgetall(key('requeues-count')) requeues.delete(TOTAL_KEY) requeues end |
#reset_stats(stat_names) ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/ci/queue/redis/build_record.rb', line 117 def reset_stats(stat_names) redis.pipelined do |pipeline| stat_names.each do |stat_name| pipeline.hdel(key(stat_name), config.worker_id) end end end |
#reset_worker_error ⇒ Object
31 32 33 |
# File 'lib/ci/queue/redis/build_record.rb', line 31 def reset_worker_error redis.hdel(key('worker-errors'), config.worker_id) end |
#worker_errors ⇒ Object
27 28 29 |
# File 'lib/ci/queue/redis/build_record.rb', line 27 def worker_errors redis.hgetall(key('worker-errors')) end |