Class: RailsErrorDashboard::Commands::BatchResolveErrors
- Inherits:
-
Object
- Object
- RailsErrorDashboard::Commands::BatchResolveErrors
- Includes:
- Translation
- 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.
Methods included from Translation
Constructor Details
#initialize(error_ids, resolved_by_name = nil, resolution_comment = nil) ⇒ BatchResolveErrors
Returns a new instance of BatchResolveErrors.
14 15 16 17 18 |
# File 'lib/rails_error_dashboard/commands/batch_resolve_errors.rb', line 14 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
10 11 12 |
# File 'lib/rails_error_dashboard/commands/batch_resolve_errors.rb', line 10 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
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 58 59 60 |
# File 'lib/rails_error_dashboard/commands/batch_resolve_errors.rb', line 20 def call return { success: false, count: 0, errors: [ red_t("red.commands.no_error_ids") ] } 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, status: "resolved" ) 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? ? [] : [ red_tp("red.commands.batch_failed.resolve", count: failed_ids.size) ] } rescue => e RailsErrorDashboard::Logger.error("Batch resolve failed: #{e.}") { success: false, count: 0, total: @error_ids.size, errors: [ e. ] } end |