Sha256: 65e7574cb884b38e2a88a1d42415ad5da82bf9f87a0f543dd8607fdc4b87f5f1

Contents?: true

Size: 1.63 KB

Versions: 42

Compression:

Stored size: 1.63 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 |pipeline|
            pipeline.lpush(
              key('error-reports'),
              payload.force_encoding(Encoding::BINARY),
            )
            pipeline.expire(key('error-reports'), config.redis_ttl)
            record_stats(stats, pipeline: pipeline)
          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 |pipeline|
            stat_names.each { |c| pipeline.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, pipeline: redis)
          return unless stats
          stats.each do |stat_name, stat_value|
            pipeline.hset(key(stat_name), config.worker_id, stat_value)
            pipeline.expire(key(stat_name), config.redis_ttl)
          end
        end
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
ci-queue-0.62.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.61.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.60.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.59.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.58.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.57.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.56.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.55.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.52.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.51.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.50.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.49.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.48.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.47.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.46.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.45.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.44.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.43.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.42.0 lib/ci/queue/redis/grind_record.rb
ci-queue-0.41.0 lib/ci/queue/redis/grind_record.rb