Class: SpreeCmCommissioner::AuditEventJob

Inherits:
ApplicationUniqueJob show all
Defined in:
app/jobs/spree_cm_commissioner/audit_event_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/jobs/spree_cm_commissioner/audit_event_job.rb', line 3

def perform(options = {})
  SpreeCmCommissioner::AuditEvent.create!(
    event_type: options[:event_type],
    success: options.fetch(:success, true),
    auditable: options[:auditable],
    user: options[:user],
    correlation_id: options[:correlation_id],
    attempt: options.fetch(:attempt, 0),
    metadata: options.fetch(:metadata, {}),
    retention_until: options[:retention_until]
  )
rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved => e
  # Log validation errors but don't retry - these are data issues, not transient failures
  CmAppLogger.log(
    label: 'AuditEventJob validation failed - non-retryable',
    data: {
      event_type: options[:event_type],
      error_class: e.class.name,
      error_message: e.message,
      validation_errors: e.record&.errors&.full_messages
    }
  )
  # Return nil to indicate the job completed (but audit wasn't saved)
  nil
end