Class: RailsErrorDashboard::Commands::BatchMuteErrors
- Inherits:
-
Object
- Object
- RailsErrorDashboard::Commands::BatchMuteErrors
- Includes:
- Translation
- Defined in:
- lib/rails_error_dashboard/commands/batch_mute_errors.rb
Overview
Command: Mute multiple errors at once
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(error_ids, muted_by = nil, reason = nil) ⇒ BatchMuteErrors
constructor
A new instance of BatchMuteErrors.
Methods included from Translation
Constructor Details
#initialize(error_ids, muted_by = nil, reason = nil) ⇒ BatchMuteErrors
Returns a new instance of BatchMuteErrors.
13 14 15 16 17 |
# File 'lib/rails_error_dashboard/commands/batch_mute_errors.rb', line 13 def initialize(error_ids, muted_by = nil, reason = nil) @error_ids = Array(error_ids).compact @muted_by = muted_by @reason = reason end |
Class Method Details
.call(error_ids, muted_by: nil, reason: nil) ⇒ Object
9 10 11 |
# File 'lib/rails_error_dashboard/commands/batch_mute_errors.rb', line 9 def self.call(error_ids, muted_by: nil, reason: nil) new(error_ids, muted_by, reason).call end |
Instance Method Details
#call ⇒ Object
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 |
# File 'lib/rails_error_dashboard/commands/batch_mute_errors.rb', line 19 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) muted_count = 0 failed_ids = [] muted_errors = [] errors.each do |error| begin error.update!( muted: true, muted_at: Time.current, muted_by: @muted_by, muted_reason: @reason ) muted_count += 1 muted_errors << error rescue => e failed_ids << error.id RailsErrorDashboard::Logger.error("Failed to mute error #{error.id}: #{e.}") end end PluginRegistry.dispatch(:on_errors_batch_muted, muted_errors) if muted_errors.any? { success: failed_ids.empty?, count: muted_count, total: @error_ids.size, failed_ids: failed_ids, errors: failed_ids.empty? ? [] : [ red_tp("red.commands.batch_failed.mute", count: failed_ids.size) ] } rescue => e RailsErrorDashboard::Logger.error("Batch mute failed: #{e.}") { success: false, count: 0, total: @error_ids.size, errors: [ e. ] } end |