Sha256: f3dd8e0b1b2fde220f2a315a7011bc55381e53a6130143e9f27a47269d2d60e4

Contents?: true

Size: 1.43 KB

Versions: 18

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true
module CI
  module Queue
    module Redis
      class GrindRecord

        def initialize(queue, redis, config)
          @queue = queue
          @redis = redis
          @config = config
        end

        def record_error(payload, stats: nil)
          redis.pipelined do
            redis.lpush(
              key('error-reports'),
              payload.force_encoding(Encoding::BINARY),
            )
            record_stats(stats)
          end
          nil
        end

        def record_success(stats: nil)
          record_stats(stats)
        end

        def record_warning(_,_)
          #do nothing
        end

        def error_reports
          redis.lrange(key('error-reports'), 0, -1)
        end

        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

        def pop_warnings
          []
        end

        alias failed_tests error_reports

        private

        attr_reader :redis, :config

        def key(*args)
          ['build', config.build_id, *args].join(':')
        end

        def record_stats(stats)
          return unless stats
          stats.each do |stat_name, stat_value|
            redis.hset(key(stat_name), config.worker_id, stat_value)
          end
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
ci-queue-0.22.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.21.1 lib/ci/queue/redis/grind_record.rb
ci-queue-0.21.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.20.9 lib/ci/queue/redis/grind_record.rb
ci-queue-0.20.8 lib/ci/queue/redis/grind_record.rb
ci-queue-0.20.7 lib/ci/queue/redis/grind_record.rb
ci-queue-0.20.6 lib/ci/queue/redis/grind_record.rb
ci-queue-0.20.5 lib/ci/queue/redis/grind_record.rb
ci-queue-0.20.4 lib/ci/queue/redis/grind_record.rb
ci-queue-0.20.3 lib/ci/queue/redis/grind_record.rb
ci-queue-0.20.2 lib/ci/queue/redis/grind_record.rb
ci-queue-0.20.1 lib/ci/queue/redis/grind_record.rb
ci-queue-0.20.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.19.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.18.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.17.2 lib/ci/queue/redis/grind_record.rb
ci-queue-0.17.1 lib/ci/queue/redis/grind_record.rb
ci-queue-0.17.0 lib/ci/queue/redis/grind_record.rb