Skip to content

Instantly share code, notes, and snippets.

@pelletencate
Last active February 28, 2020 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pelletencate/80cbcc24ce988223a8e3a4ac84d930cf to your computer and use it in GitHub Desktop.
Save pelletencate/80cbcc24ce988223a8e3a4ac84d930cf to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require 'rspec/core/formatters/base_text_formatter'
class QueueFormatter < RSpec::Core::Formatters::BaseTextFormatter
# This registers the notifications this formatter supports, and tells
# us that this was written against the RSpec 3.x formatter API.
RSpec::Core::Formatters.register self, :example_started, :example_failed
def initialize(output)
@output = output
@started_at = Time.now
end
def example_started(notification)
@output.puts 'START: ' \
"worker=#{ENV['CI_NODE_INDEX']} " \
"errors=#{$redis.hlen("#{build}error-reports")} " \
"warnings=#{$redis.hlen("#{build}error-reports")} " \
"requeues=#{$redis.hget("#{build}requeues-count", '___total___').to_i} " \
"master=#{$redis.get("#{build}master-status")} " \
"workers=#{$redis.smembers("#{build}workers").size} " \
"running=#{$redis.smembers("#{build}workers").size} " \
"processed=#{$redis.smembers("#{build}processed").size} " \
"worker-queue=#{$redis.llen("#{build}worker:#{ENV['CI_NODE_INDEX'].to_i}:queue")} " \
"total-queue=#{$redis.llen("#{build}queue")} " \
"time=#{(Time.now - @started_at).to_i} " \
"path=#{notification.example.location}"
end
def example_failed(notification)
@output.puts "\nFAIL: #{notification.example.location}\n"
end
def build
@build ||= "build:#{$redis.keys.detect { |k| k =~ /\Abuild:/ }&.split(':').try(:[], 1)}:"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment