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_requeue(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
103 104 105 |
# File 'lib/ci/queue/redis/build_record.rb', line 103 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
111 112 113 114 115 116 117 118 119 |
# File 'lib/ci/queue/redis/build_record.rb', line 111 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
107 108 109 |
# File 'lib/ci/queue/redis/build_record.rb', line 107 def flaky_reports redis.smembers(key('flaky-reports')) end |
#max_test_failed? ⇒ Boolean
97 98 99 100 101 |
# File 'lib/ci/queue/redis/build_record.rb', line 97 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 |
# File 'lib/ci/queue/redis/build_record.rb', line 59 def record_error(id, payload, stats: nil) acknowledged, _ = redis.pipelined do |pipeline| @queue.acknowledge(id, error: payload, pipeline: pipeline) record_stats(stats, pipeline: pipeline) end @queue.increment_test_failed if acknowledged == 1 nil end |
#record_flaky(id, stats: nil) ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ci/queue/redis/build_record.rb', line 86 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_requeue(id, stats: nil) ⇒ Object
80 81 82 83 84 |
# File 'lib/ci/queue/redis/build_record.rb', line 80 def record_requeue(id, stats: nil) redis.pipelined do |pipeline| record_stats(stats, pipeline: pipeline) end end |
#record_success(id, stats: nil, skip_flaky_record: false) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ci/queue/redis/build_record.rb', line 69 def record_success(id, stats: nil, skip_flaky_record: false) _, error_reports_deleted_count, requeued_count, _ = redis.multi do |transaction| @queue.acknowledge(id, pipeline: transaction) transaction.hdel(key('error-reports'), id) transaction.hget(key('requeues-count'), id) record_stats(stats, pipeline: transaction) 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
121 122 123 124 125 126 127 |
# File 'lib/ci/queue/redis/build_record.rb', line 121 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 |