Class: Recheck::Reporter::Cron
- Inherits:
-
Base
- Object
- Base
- Recheck::Reporter::Cron
show all
- Defined in:
- lib/recheck/reporters.rb
Overview
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#around_query, #fetch_record_id, inherited
Constructor Details
#initialize(arg:) ⇒ Cron
Returns a new instance of Cron.
71
72
73
74
|
# File 'lib/recheck/reporters.rb', line 71
def initialize(arg:)
raise ArgumentError, "does not take options" unless arg.nil?
@errors = []
end
|
Class Method Details
.help ⇒ Object
67
68
69
|
# File 'lib/recheck/reporters.rb', line 67
def self.help
"Prints failures/exceptions but nothing on pass. For use in cron jobs, which use silence to incidate success."
end
|
Instance Method Details
#around_check(checker:, query:, check:, record:) ⇒ Object
95
96
97
98
|
# File 'lib/recheck/reporters.rb', line 95
def around_check(checker:, query:, check:, record:)
result = yield
@errors << result if result.is_a? Error
end
|
#around_checker(checker:, queries:, checks:) ⇒ Object
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/recheck/reporters.rb', line 84
def around_checker(checker:, queries:, checks:)
@errors = []
counts = yield
if counts.any_errors?
puts "#{checker.class}: #{counts.summary}"
print_errors
end
end
|
#around_run(checkers: []) ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/recheck/reporters.rb', line 76
def around_run(checkers: [])
total_counts = yield
if total_counts.any_errors?
puts "Total: #{total_counts.summary}"
end
end
|
#halt(checker:, query:, error:, check: nil) ⇒ Object
100
101
102
|
# File 'lib/recheck/reporters.rb', line 100
def halt(checker:, query:, error:, check: nil)
@errors << error
end
|
#print_errors ⇒ Object
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/recheck/reporters.rb', line 104
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}##{query} -> #{check} failed for records: #{ids}"
when :exception
error = group_errors.first
error_message = " #{checker}##{query} -> #{check} exception #{error.exception.message} for #{group_errors.size} records"
failure_details << error_message
failure_details << error.record.full_message(highlight: false, order: :top) if error.record.respond_to?(:full_message)
when :blanket
failure_details << " #{checker}: Skipping because the first 20 checks all failed. Either there's a lot of bad data or there's something wrong with the checks."
end
end
puts failure_details
end
|