Class: NdrError::Fingerprint
- Inherits:
-
Object
- Object
- NdrError::Fingerprint
- Defined in:
- app/models/ndr_error/fingerprint.rb
Overview
Fingerprints group together similar error occurences.
Class Method Summary collapse
- .filter_by_keywords(keywords) ⇒ Object
-
.find_or_create_by_id(digest) ⇒ Object
Gets a fingerprint record for the given MD5 digest.
Instance Method Summary collapse
-
#ensure_ticket_url_matched_a_supplied_format ⇒ Object
Optionally, NdrError can validate ticket urls:.
-
#first_occurrence ⇒ Object
Returns the record corresponding to the first occurrence of this type of error.
-
#latest_occurrence ⇒ Object
Returns the record corresponding to the most recent occurrence of this type of error.
-
#purge! ⇒ Object
Remove all instances of the error, but keep the fingerprint record for the future.
-
#store_log(log, bypass_limit = false) ⇒ Object
Saves the supplied log unless there is already deemed to be enough evidence.
Class Method Details
.filter_by_keywords(keywords) ⇒ Object
33 34 35 36 37 38 39 |
# File 'app/models/ndr_error/fingerprint.rb', line 33 def self.filter_by_keywords(keywords) md5_match = keywords.map do |part| sanitize_sql(["#{table_name}.#{primary_key} LIKE ?", "%#{part}%"]) end.join(' OR ') where(md5_match) end |
.find_or_create_by_id(digest) ⇒ Object
Gets a fingerprint record for the given MD5 digest.
43 44 45 46 47 48 49 50 |
# File 'app/models/ndr_error/fingerprint.rb', line 43 def self.find_or_create_by_id(digest) existing = find_by(error_fingerprintid: digest) existing || create do |print| print.count = 0 print.error_fingerprintid = digest end end |
Instance Method Details
#ensure_ticket_url_matched_a_supplied_format ⇒ Object
Optionally, NdrError can validate ticket urls:
53 54 55 56 |
# File 'app/models/ndr_error/fingerprint.rb', line 53 def ensure_ticket_url_matched_a_supplied_format return unless NdrError.ticket_url_format && ticket_url.present? errors.add(:ticket_url, 'has bad format!') if ticket_url !~ NdrError.ticket_url_format end |
#first_occurrence ⇒ Object
Returns the record corresponding to the first occurrence of this type of error.
85 86 87 |
# File 'app/models/ndr_error/fingerprint.rb', line 85 def first_occurrence error_logs.not_deleted.last end |
#latest_occurrence ⇒ Object
Returns the record corresponding to the most recent occurrence of this type of error.
92 93 94 |
# File 'app/models/ndr_error/fingerprint.rb', line 92 def latest_occurrence error_logs.not_deleted.first end |
#purge! ⇒ Object
Remove all instances of the error, but keep the fingerprint record for the future.
60 61 62 |
# File 'app/models/ndr_error/fingerprint.rb', line 60 def purge! error_logs.each(&:flag_as_deleted!) end |
#store_log(log, bypass_limit = false) ⇒ Object
Saves the supplied log unless there is already deemed to be enough evidence. Stores an updated count regardless, though.
‘bypass_limit’ can be set to true in order to force creation of a new log record.
71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/models/ndr_error/fingerprint.rb', line 71 def store_log(log, bypass_limit = false) if bypass_limit || (error_logs.not_deleted.count < NdrError.fingerprint_threshold) error_logs << log end self.count += 1 save! # Don't return the log if it was discarded: log.new_record? ? nil : log end |