Class: RailsErrorDashboard::Commands::BatchResolveErrors
- Inherits:
-
Object
- Object
- RailsErrorDashboard::Commands::BatchResolveErrors
- Defined in:
- lib/rails_error_dashboard/commands/batch_resolve_errors.rb
Overview
Command: Resolve multiple errors at once This is a write operation that updates multiple ErrorLog records
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(error_ids, resolved_by_name = nil, resolution_comment = nil) ⇒ BatchResolveErrors
constructor
A new instance of BatchResolveErrors.
Constructor Details
#initialize(error_ids, resolved_by_name = nil, resolution_comment = nil) ⇒ BatchResolveErrors
Returns a new instance of BatchResolveErrors.
12 13 14 15 16 |
# File 'lib/rails_error_dashboard/commands/batch_resolve_errors.rb', line 12 def initialize(error_ids, resolved_by_name = nil, resolution_comment = nil) @error_ids = Array(error_ids).compact @resolved_by_name = resolved_by_name @resolution_comment = resolution_comment end |
Class Method Details
.call(error_ids, resolved_by_name: nil, resolution_comment: nil) ⇒ Object
8 9 10 |
# File 'lib/rails_error_dashboard/commands/batch_resolve_errors.rb', line 8 def self.call(error_ids, resolved_by_name: nil, resolution_comment: nil) new(error_ids, resolved_by_name, resolution_comment).call end |
Instance Method Details
#call ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rails_error_dashboard/commands/batch_resolve_errors.rb', line 18 def call return { success: false, count: 0, errors: [ "No error IDs provided" ] } if @error_ids.empty? errors = ErrorLog.where(id: @error_ids) resolved_count = 0 failed_ids = [] resolved_errors = [] errors.each do |error| begin error.update!( resolved: true, resolved_at: Time.current, resolved_by_name: @resolved_by_name, resolution_comment: @resolution_comment ) resolved_count += 1 resolved_errors << error rescue => e failed_ids << error.id RailsErrorDashboard::Logger.error("Failed to resolve error #{error.id}: #{e.}") end end # Dispatch plugin event for batch resolved errors PluginRegistry.dispatch(:on_errors_batch_resolved, resolved_errors) if resolved_errors.any? { success: failed_ids.empty?, count: resolved_count, total: @error_ids.size, failed_ids: failed_ids, errors: failed_ids.empty? ? [] : [ "Failed to resolve #{failed_ids.size} error(s)" ] } rescue => e RailsErrorDashboard::Logger.error("Batch resolve failed: #{e.}") { success: false, count: 0, total: @error_ids.size, errors: [ e. ] } end |