Class: Edi::Openai::Sender

Inherits:
BaseEdiService show all
Defined in:
app/services/edi/openai/sender.rb

Overview

Transmits staged product_data ECLs to OpenAI's commerce SFTP drop.

OpenAI answers the SFTP close with a non-OK status even on success (the
bytes are already written), so the close code is NOT authoritative. Delivery is
confirmed deterministically by reading the uploaded file back and checksum-
matching it against what we sent. OpenAI then ingests the dropped file on its
own ASYNCHRONOUS schedule and records the outcome in a sibling status.json
captured here as an informational signal that does NOT gate delivery. (Gating
on status.json freshness raced OpenAI's async ingestion and flapped every run
to exception despite a successful upload — AppSignal #6056 / #6062 / #6063.)

Constant Summary collapse

STATUS_FILENAME =
'status.json'

Constants included from AddressAbbreviator

AddressAbbreviator::MAX_LENGTH

Instance Attribute Summary

Attributes inherited from BaseEdiService

#orchestrator

Attributes inherited from BaseService

#options

Instance Method Summary collapse

Methods inherited from BaseEdiService

#duplicate_po_already_notified?, #initialize, #mark_duplicate_po_as_notified, #report_order_creation_issues, #safe_process_edi_communication_log

Methods included from AddressAbbreviator

#abbreviate_street, #collect_street_originals, #record_address_abbreviation_notes

Methods inherited from BaseService

#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #tagged_logger

Constructor Details

This class inherits a constructor from Edi::BaseEdiService

Instance Method Details

#process(edi_communication_logs = nil) ⇒ Object

Returns the processed logs.

Parameters:

  • edi_communication_logs (Enumerable<EdiCommunicationLog>, nil) (defaults to: nil)

    defaults
    to this partner's ready/retry product_data logs.

Returns:

  • the processed logs.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/edi/openai/sender.rb', line 23

def process(edi_communication_logs = nil)
  # Materialize before delivering: `deliver` flips each ECL's state, so a
  # lazy `requiring_processing` relation would re-query to an empty set.
  logs = Array(
    edi_communication_logs || EdiCommunicationLog.requiring_processing
                                                 .where(partner: orchestrator.partner, category: 'product_data')
                                                 .order(:created_at)
                                                 .to_a
  )
  logs.each { |ecl| deliver(ecl) }
  logs
end