Class: SpreeCmCommissioner::MaintenanceTasks::GuestDataFillStageBatchJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/spree_cm_commissioner/maintenance_tasks/guest_data_fill_stage_batch_job.rb

Instance Method Summary collapse

Methods included from ApplicationJobDecorator

handle_deserialization_error, prepended

Instance Method Details

#perform(guest_ids:, notify: true) ⇒ Object

Refreshes data_fill_stage (+ clears has_incomplete_guest_info caches, and optionally notifies newly-incomplete guests) for a bounded batch of guests. Enqueued in slices by MaintenanceTasks::GuestDataFillStage#maintain and by the recompute_guest_data_fill_stage rake task instead of looping over every guest inline, so neither a product with many completed-order guests nor a full-table backfill blocks a single job for a long time.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/jobs/spree_cm_commissioner/maintenance_tasks/guest_data_fill_stage_batch_job.rb', line 11

def perform(guest_ids:, notify: true)
  SpreeCmCommissioner::Guest
    .where(id: guest_ids)
    .includes(line_item: :order)
    .find_each do |guest|
      result = SpreeCmCommissioner::Guests::RefreshDataFillStage.call(guest: guest, notify: notify)

      next if result.success?

      CmAppLogger.log(
        label: "#{self.class.name} failed",
        data: { guest_id: guest.id, error: result.error.to_s }
      )
    end
end