Class: Spree::ReportSubscriber

Inherits:
Subscriber show all
Defined in:
app/subscribers/spree/report_subscriber.rb

Overview

Handles Report lifecycle events.

This subscriber replaces the following callbacks in Spree::Report:

  • after_commit :generate_async, on: :create

When a report is created, this subscriber triggers the async generation job.

We use async: false because this subscriber just queues a background job, so there’s no benefit to running the subscriber itself asynchronously.

Instance Method Summary collapse

Methods inherited from Subscriber

#call, call, event_handlers, #handle, on, subscribes_to, subscription_options, subscription_patterns

Instance Method Details

#generate_report_async(event) ⇒ Object



19
20
21
22
23
24
# File 'app/subscribers/spree/report_subscriber.rb', line 19

def generate_report_async(event)
  report_id = event.payload['id']
  return unless report_id

  Spree::Reports::GenerateJob.perform_later(report_id)
end