Class: Recheck::Reporter::Default

Inherits:
Base
  • Object
show all
Defined in:
lib/recheck/reporters.rb

Overview

Cron

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#around_query, #fetch_record_id, inherited

Constructor Details

#initialize(arg:) ⇒ Default

Returns a new instance of Default.

Raises:

  • (ArgumentError)


131
132
133
134
135
# File 'lib/recheck/reporters.rb', line 131

def initialize(arg:)
  raise ArgumentError, "does not take options" unless arg.nil?
  @current_counts = CountStats.new
  @errors = []
end

Class Method Details

.helpObject



127
128
129
# File 'lib/recheck/reporters.rb', line 127

def self.help
  "Used when no --reporter is named. Prints incremental progress to stdout. No options."
end

Instance Method Details

#around_check(checker:, query:, check:, record:) ⇒ Object



160
161
162
163
164
165
166
167
# File 'lib/recheck/reporters.rb', line 160

def around_check(checker:, query:, check:, record:)
  result = yield

  @current_counts.increment(result.type)
  print_progress if @current_counts.total % 1000 == 0

  @errors << result if result.is_a? Error
end

#around_checker(checker:, queries:, checks:, check: []) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/recheck/reporters.rb', line 146

def around_checker(checker:, queries:, checks:, check: [])
  @errors = []

  print "#{checker.class}: "
  counts = yield

  # don't double-print last progress indicator
  print_progress unless @current_counts.total % 1000 == 0
  print_check_summary(counts)
  print_errors

  counts
end

#around_run(checkers: []) ⇒ Object



137
138
139
140
141
142
143
144
# File 'lib/recheck/reporters.rb', line 137

def around_run(checkers: [])
  total_counts = yield

  puts "Total: #{total_counts.summary}"
  puts "Queries found no records to check (this is OK when a checker queries for invalid data)" if total_counts.all_zero?

  total_counts
end

#halt(checker:, query:, error:, check: nil) ⇒ Object



169
170
171
# File 'lib/recheck/reporters.rb', line 169

def halt(checker:, query:, error:, check: nil)
  @errors << error
end


173
174
175
# File 'lib/recheck/reporters.rb', line 173

def print_check_summary(counts)
  puts "  #{counts.summary}"
end


177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/recheck/reporters.rb', line 177

def print_errors
  failure_details = []
  grouped_errors = @errors.group_by { |e| [e.checker, e.query, e.check, e.type] }

  grouped_errors.each do |(checker, query, check), group_errors|
    case group_errors.first.type
    when :fail
      ids = group_errors.map { |e| fetch_record_id(e.record) }.join(", ")
      failure_details << "  #{checker.class}##{query} -> #{check} failed for records: #{ids}"
    when :exception
      error = group_errors.first
      error_message = "  #{checker.class}##{query} -> #{check} exception #{error.exception.message} for #{group_errors.size} records"
      failure_details << error_message
      failure_details << error.exception.full_message(highlight: false, order: :top) if error.exception.respond_to?(:full_message)
    when :no_query_methods
      failure_details << "  #{checker.class}: Did not define .query_methods"
    when :no_queries
      failure_details << "  #{checker.class} Defines .query_methods, but it didn't return any"
    when :no_check_methods
      failure_details << "  #{checker.class}: Did not define .check_methods"
    when :no_checks
      failure_details << "  #{checker.class} Defines .check_methods, but it didn't return any"
    when :blanket
      failure_details << "  #{checker.class}: Skipping because the first 20 checks all failed. Either there's a lot of bad data or there's something wrong with the checker."
    else
      failure_details << "  #{checker.class} unknown error"
    end
  end
  puts failure_details
end


208
209
210
211
# File 'lib/recheck/reporters.rb', line 208

def print_progress
  print @current_counts.all_pass? ? "." : "x"
  @current_counts = CountStats.new
end