Class: Edi::BaseEdiService
- Inherits:
-
BaseService
- Object
- BaseService
- Edi::BaseEdiService
- Includes:
- AddressAbbreviator, RequestIdentifiable
- Defined in:
- app/services/edi/base_edi_service.rb
Overview
Service object: base edi service.
Direct Known Subclasses
Amazon::APlusContentProcessor, Amazon::APlusContentRetriever, Amazon::AcknowledgeMessageSender, Amazon::BuyBoxStatusRetriever, Amazon::CatalogItemInformationProcessor, Amazon::CatalogItemInformationRetriever, Amazon::ConfirmMessageProcessor, Amazon::ConfirmMessageSender, Amazon::DeleteListingMessageProcessor, Amazon::DiscontinueFlowProcessor, Amazon::FbaOrderMessageProcessor, Amazon::FbaOrderMessageRetriever, Amazon::FeedMessageSender, Amazon::FeedSubmissionResultProcessor, Amazon::InventoryMessageProcessor, Amazon::ListingItemInformationProcessor, Amazon::ListingItemInformationRetriever, Amazon::ListingItemSchemaRetriever, Amazon::ListingMessageFeedProcessor, Amazon::ListingMessageProcessor, Amazon::OrderMessageProcessor, Amazon::OrderMessageRetriever, Amazon::OrderStatusVerifier, Amazon::PriceMessageProcessor, Amazon::ProductDataProcessor, Amazon::ReturnsReportProcessor, Amazon::ReturnsReportRetriever, Amazon::Sender, AmazonVc::AcknowledgeMessageSender, AmazonVc::CatalogItemInformationProcessor, AmazonVc::CatalogItemInformationRetriever, AmazonVc::ConfirmMessageProcessor, AmazonVc::ConfirmMessageSender, AmazonVc::DeleteListingMessageProcessor, AmazonVc::InventoryMessageProcessor, AmazonVc::InventoryMessageSender, AmazonVc::InvoiceMessageProcessor, AmazonVc::InvoiceMessageSender, AmazonVc::ListingItemInformationProcessor, AmazonVc::ListingItemInformationRetriever, AmazonVc::ListingItemValidationErrorsRetriever, AmazonVc::ListingMessageProcessor, AmazonVc::OrderMessageProcessor, AmazonVc::OrderMessageRetriever, AmazonVc::PackingSlipProcessor, AmazonVc::PackingSlipRetriever, AmazonVc::Sender, AmazonVc::TransactionMessageProcessor, Commercehub::AcknowledgeMessageSender, Commercehub::ConfirmMessageProcessor, Commercehub::ConfirmMessageSender, Commercehub::FaMessageProcessor, Commercehub::FaMessageSender, Commercehub::InventoryMessageProcessor, Commercehub::InventoryMessageSender, Commercehub::InvoiceMessageProcessor, Commercehub::InvoiceMessageSender, Commercehub::OrderMessageProcessor, Commercehub::OrderMessageRetriever, Commercehub::PackingSlipProcessor, Commercehub::PackingSlipReaderCostcoCa, Commercehub::PackingSlipReaderLowesCom, Commercehub::PackingSlipReaderRonaCa, Commercehub::PackingSlipReaderThdCa, Commercehub::PackingSlipReaderThdUs, Commercehub::PackingSlipRetriever, Commercehub::RemitMessageProcessor, Commercehub::RemitMessageRetriever, Commercehub::ReturnAuthorizationMessageRetriever, Commercehub::ReturnNotificationMessageProcessor, Commercehub::ReturnNotificationMessageSender, Google::ProductDataProcessor, Google::PromotionDataProcessor, Google::PromotionSender, Google::Sender, Menard::DiscontinueFlowProcessor, Menard::InventoryMessageProcessor, Menard::InventoryMessageSender, MftGateway::AcknowledgeMessageSender, MftGateway::ConfirmMessageProcessor, MftGateway::ConfirmMessageSender, MftGateway::InventoryMessageProcessor, MftGateway::InventoryMessageSender, MftGateway::InvoiceMessageProcessor, MftGateway::InvoiceMessageSender, MftGateway::OrderMessageProcessor, MftGateway::Sender, MiraklSeller::ConfirmMessageProcessor, MiraklSeller::ConfirmMessageSender, MiraklSeller::FaMessageProcessor, MiraklSeller::FaMessageSender, MiraklSeller::InvoiceMessageProcessor, MiraklSeller::OrderMessageProcessor, MiraklSeller::OrderMessageRetriever, MiraklSeller::PriceImportMessageProcessor, MiraklSeller::PriceMessageProcessor, MiraklSeller::PriceMessageSender, MiraklSeller::ProductDataConfigurator, MiraklSeller::ProductDataProcessor, MiraklSeller::ProductDataSender, MiraklSeller::ProductImportMessageProcessor, MiraklSeller::Sender, Openai::ProductDataProcessor, Openai::Sender, ResellerInventory::InventoryProcessor, ResellerInventory::Sender, Walmart::AcknowledgeMessageSender, Walmart::CatalogItemInformationProcessor, Walmart::CatalogItemInformationRetriever, Walmart::ConfirmMessageProcessor, Walmart::ConfirmMessageSender, Walmart::DiscontinueFlowProcessor, Walmart::FeedMessageSender, Walmart::FeedSubmissionResultProcessor, Walmart::InventoryMessageProcessor, Walmart::ListingMessageFeedProcessor, Walmart::OrderMessageProcessor, Walmart::OrderMessageRetriever, Walmart::PriceMessageProcessor, Walmart::ReturnsReportProcessor, Walmart::ReturnsReportRetriever, Wayfair::AcknowledgeMessageSender, Wayfair::CatalogItemGroupUpdateSender, Wayfair::CatalogItemInformationProcessor, Wayfair::CatalogItemInformationRetriever, Wayfair::CatalogItemInformationUpdater, Wayfair::CatalogItemMediaSender, Wayfair::CatalogItemUpdateSender, Wayfair::CatalogReadV2Retriever, Wayfair::ConfirmMessageProcessor, Wayfair::ConfirmMessageSender, Wayfair::InventoryMessageProcessor, Wayfair::InventoryMessageSender, Wayfair::OrderMessageProcessor, Wayfair::OrderMessageRetriever, Wayfair::PackingSlipRetriever, Wayfair::ProductAdditionSender, Wayfair::Sender, Wayfair::TaxonomyAttributeRetriever
Constant Summary
Constants included from RequestIdentifiable
RequestIdentifiable::REQUEST_ID_HEADERS
Constants included from AddressAbbreviator
AddressAbbreviator::MAX_LENGTH
Instance Attribute Summary collapse
-
#orchestrator ⇒ Object
readonly
Returns the value of attribute orchestrator.
Attributes inherited from BaseService
Instance Method Summary collapse
-
#amazon_feed_product_type(catalog_item) ⇒ String?
protected
Resolve the Amazon productType for a Listings feed PATCH.
-
#duplicate_po_already_notified?(po_number, current_edi_log_id) ⇒ Boolean
protected
Check if we've already sent a notification about this duplicate PO Looks for processed EDI logs with this PO that have no associated order (meaning they detected a duplicate and sent a notification).
-
#initialize(orchestrator, options = {}) ⇒ BaseEdiService
constructor
A new instance of BaseEdiService.
-
#mark_duplicate_po_as_notified(po_number, edi_log_id) ⇒ Object
protected
No-op: notification tracking is now based on processed logs without orders.
-
#onboard_ordered_catalog_items(order) ⇒ void
protected
Promote every ordered catalog item still parked in
pending_onboarding. - #report_order_creation_issues(batch_process_results) ⇒ Object protected
-
#safe_process_edi_communication_log(ecl) ⇒ Object
Contains a failure to the one log it belongs to, so the rest of the batch still gets processed.
Methods included from RequestIdentifiable
Methods included from AddressAbbreviator
#abbreviate_street, #collect_street_originals, #record_address_abbreviation_notes
Methods inherited from BaseService
#log_debug, #log_error, #log_info, #log_warning, #logger, #process, #tagged_logger
Constructor Details
#initialize(orchestrator, options = {}) ⇒ BaseEdiService
Returns a new instance of BaseEdiService.
14 15 16 17 |
# File 'app/services/edi/base_edi_service.rb', line 14 def initialize(orchestrator, = {}) @orchestrator = orchestrator super() end |
Instance Attribute Details
#orchestrator ⇒ Object (readonly)
Returns the value of attribute orchestrator.
9 10 11 |
# File 'app/services/edi/base_edi_service.rb', line 9 def orchestrator @orchestrator end |
Instance Method Details
#amazon_feed_product_type(catalog_item) ⇒ String? (protected)
Resolve the Amazon productType for a Listings feed PATCH. Delegates to the
Listings-Items path so the two can never drift — the feed and the
listing PUT/PATCH must submit the SAME productType for the same item. See
Models::CatalogItemAmazonHelper#amazon_product_type_in_effect for the precedence (reported
before desired) and why an unlaunched desired type must never be submitted.
Returns nil when nothing is known — callers MUST skip the item rather than
guessing, so we never register a wrong product type.
59 60 61 |
# File 'app/services/edi/base_edi_service.rb', line 59 def amazon_feed_product_type(catalog_item) catalog_item.amazon_product_type_in_effect end |
#duplicate_po_already_notified?(po_number, current_edi_log_id) ⇒ Boolean (protected)
Check if we've already sent a notification about this duplicate PO
Looks for processed EDI logs with this PO that have no associated order
(meaning they detected a duplicate and sent a notification)
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/services/edi/base_edi_service.rb', line 73 def duplicate_po_already_notified?(po_number, current_edi_log_id) return false if po_number.blank? # Find processed EDI logs for this partner that: # 1. Contain this PO in their data # 2. Have NO associated orders (meaning they didn't create an order = duplicate detection) EdiCommunicationLog .where(partner: orchestrator.partner, category: 'order_batch') .where(state: 'processed') .where('edi_communication_logs.created_at > ?', 30.days.ago) .where.not(edi_communication_logs: { id: current_edi_log_id.to_i }) .where('edi_communication_logs.data LIKE ?', "%#{po_number}%") .where.missing(:orders) .exists? end |
#mark_duplicate_po_as_notified(po_number, edi_log_id) ⇒ Object (protected)
No-op: notification tracking is now based on processed logs without orders
90 91 92 93 |
# File 'app/services/edi/base_edi_service.rb', line 90 def mark_duplicate_po_as_notified(po_number, edi_log_id) # Tracking is implicit: when this log is marked 'processed' without creating an order, # future checks will find it and skip sending duplicate notifications end |
#onboard_ordered_catalog_items(order) ⇒ void (protected)
This method returns an undefined value.
Promote every ordered catalog item still parked in pending_onboarding.
A retailer only transmits an order for a SKU it actually sells, so the
order is proof the listing is live — see CatalogItem#onboarded_by_order!.
Call this ONLY once the order is fully built. Promoting mid-build would
survive a rejected order: several processors rescue per-order INSIDE the
batch transaction (Edi::Amazon::OrderMessageProcessor#process_orders),
so the transaction commits even when a line raised.
45 46 47 |
# File 'app/services/edi/base_edi_service.rb', line 45 def onboard_ordered_catalog_items(order) order.line_items.each { |line_item| line_item.catalog_item&.onboarded_by_order! } end |
#report_order_creation_issues(batch_process_results) ⇒ Object (protected)
63 64 65 66 67 68 |
# File 'app/services/edi/base_edi_service.rb', line 63 def report_order_creation_issues(batch_process_results) orders_created = batch_process_results.flat_map(&:orders_created) if (orders_to_report = orders_created.to_a.select(&:requires_intervention?)).present? EdiMailer.edi_orders_notification(orders_to_report).deliver_later end end |
#safe_process_edi_communication_log(ecl) ⇒ Object
Contains a failure to the one log it belongs to, so the rest of the batch
still gets processed. can_error? matters: a processor that already
errored the record before raising would otherwise hit InvalidTransition
here, and that escapes the rescue and kills the whole loop.
23 24 25 26 27 28 29 30 31 |
# File 'app/services/edi/base_edi_service.rb', line 23 def safe_process_edi_communication_log(ecl) process_communication_log(ecl) rescue StandardError => e msg = "Exception while processing edi_communication_log #{ecl.id}: #{e}" ErrorReporting.error(e, msg) ecl.notes = msg ecl.can_error? ? ecl.error! : ecl.save logger.error msg end |