Class: SpreeCmCommissioner::QueueDraftOrders::Process

Inherits:
Object
  • Object
show all
Includes:
Spree::ServiceModule::Base
Defined in:
app/services/spree_cm_commissioner/queue_draft_orders/process.rb

Overview

Performs the real order creation for a queued draft order and publishes the outcome back onto its Firestore status document. This is where line_items are actually validated (stock, promotions, everything DraftOrders::Create checks) — Enqueue only did a cheap presence check before creating the document and scheduling QueueDraftOrders::ProcessJob, which just calls this.

On failure, the document's error_message carries DraftOrders::Create's raw (already localized) failure text straight through — no attempt to classify why it failed into a reason code. An earlier revision tried that (rendering DraftOrders::Create's translation templates with a sentinel value to pattern-match the raw message back into out_of_stock/validation_error/etc.), but nothing on the app side ever consumed the distinction — it always just showed error_message as-is — so the classification was speculative complexity with no reader. Simplified back to what's actually used; revisit with a real mechanism (e.g. DraftOrders::Create returning a structured error code) if a future feature genuinely needs per-failure-type UI.

Instance Method Summary collapse

Instance Method Details

#call(document_path:, create_type:, creation_params:) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/services/spree_cm_commissioner/queue_draft_orders/process.rb', line 20

def call(document_path:, create_type:, creation_params:)
  publish_processing(document_path)

  result = create_order(create_type, creation_params)

  if result.success?
    publish_completed(document_path, result.value[:order])
    return success(document_path)
  end

  fail_with(document_path, result.error.to_s)
rescue StandardError => e
  # Caught here rather than left to propagate: the Firestore document still needs its
  # `failed` write regardless of *why* create_order blew up (e.g. an unrecognized
  # create_type), and `Spree::ServiceModule::Base`'s failure/Result contract already gives
  # the job a way to know something went wrong without an exception — no need to also raise.
  fail_with(document_path, e.message)
end