Class: Chronicle::ErrorLogs::GroupResolver
- Inherits:
-
Object
- Object
- Chronicle::ErrorLogs::GroupResolver
- Defined in:
- app/services/chronicle/error_logs/group_resolver.rb
Overview
Resolves the ErrorGroup for a new ErrorLog.
Responsibilities:
- Derive the fingerprint (use the caller-supplied one, or compute from
the log's structural identity if none was given).
- Find an existing group for that fingerprint and increment its
occurrence tracking.
- Create a brand-new group when none exists yet.
- Handle the concurrent-insert race condition transparently.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(error_log) ⇒ GroupResolver
constructor
A new instance of GroupResolver.
Constructor Details
#initialize(error_log) ⇒ GroupResolver
Returns a new instance of GroupResolver.
13 14 15 |
# File 'app/services/chronicle/error_logs/group_resolver.rb', line 13 def initialize(error_log) @error_log = error_log end |
Instance Method Details
#call ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'app/services/chronicle/error_logs/group_resolver.rb', line 17 def call existing = ErrorGroup.find_by(project: error_log.project, fingerprint: fingerprint) return bump_occurrence(existing) if existing create_group rescue ActiveRecord::RecordNotUnique # A concurrent request won the INSERT race. Find the winner and record # this occurrence against it so the count stays accurate. bump_occurrence(ErrorGroup.find_by!(project: error_log.project, fingerprint: fingerprint)) end |