Module: Workers::ErrorReportingConcern

Extended by:
ActiveSupport::Concern
Defined in:
app/concerns/workers/error_reporting_concern.rb

Overview

Concern for Sidekiq workers that need to manually report errors
while continuing execution (e.g., batch processing).

Usage:
class MyWorker
include Sidekiq::Job
include Workers::ErrorReportingConcern

def perform(ids)
  ids.each do |id|
    process_item(id)
  rescue StandardError => e
    report_worker_error(e, item_id: id)
    # Continue with next item
  end
end

end

Instance Method Summary collapse

Instance Method Details

#report_worker_error(exception, context = {}) ⇒ Object

Report an error with worker context

Parameters:

  • exception (Exception, String)

    The error to report

  • context (Hash) (defaults to: {})

    Additional context to include



28
29
30
31
# File 'app/concerns/workers/error_reporting_concern.rb', line 28

def report_worker_error(exception, context = {})
  full_context = worker_context.merge(context)
  ErrorReporting.error(exception, full_context)
end

#report_worker_warning(message, context = {}) ⇒ Object

Report a warning with worker context

Parameters:

  • message (String, Exception)

    The warning to report

  • context (Hash) (defaults to: {})

    Additional context to include



36
37
38
39
# File 'app/concerns/workers/error_reporting_concern.rb', line 36

def report_worker_warning(message, context = {})
  full_context = worker_context.merge(context)
  ErrorReporting.warning(message, full_context)
end