Class: CI::Queue::Redis::BuildRecord
- Inherits:
-
Object
- Object
- CI::Queue::Redis::BuildRecord
- Defined in:
- lib/ci/queue/redis/build_record.rb
Defined Under Namespace
Classes: Test
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, acknowledge: true) ⇒ 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
98 99 100 |
# File 'lib/ci/queue/redis/build_record.rb', line 98 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
106 107 108 109 110 111 112 113 114 |
# File 'lib/ci/queue/redis/build_record.rb', line 106 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
102 103 104 |
# File 'lib/ci/queue/redis/build_record.rb', line 102 def flaky_reports redis.smembers(key('flaky-reports')) end |
#max_test_failed? ⇒ Boolean
92 93 94 95 96 |
# File 'lib/ci/queue/redis/build_record.rb', line 92 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
61 62 63 64 65 66 67 68 |
# File 'lib/ci/queue/redis/build_record.rb', line 61 def record_error(id, payload, stats: nil) redis.pipelined do |pipeline| @queue.acknowledge(id, error: payload, pipeline: pipeline) record_stats(stats, pipeline: pipeline) @queue.increment_test_failed(pipeline: pipeline) end nil end |
#record_flaky(id, stats: nil) ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ci/queue/redis/build_record.rb', line 81 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, acknowledge: true) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ci/queue/redis/build_record.rb', line 70 def record_success(id, stats: nil, skip_flaky_record: false, acknowledge: true) @queue.acknowledge(id) if acknowledge error_reports_deleted_count, requeued_count, _ = redis.pipelined do |pipeline| pipeline.hdel(key('error-reports'), id) pipeline.hget(key('requeues-count'), id) 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
116 117 118 119 120 121 122 |
# File 'lib/ci/queue/redis/build_record.rb', line 116 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 |