Class: VendorsService::InventorySync::RestaurantService
- Inherits:
-
Object
- Object
- VendorsService::InventorySync::RestaurantService
- Includes:
- ElasticAPM::SpanHelpers, SupplierConfig
- Defined in:
- app/services/vendors_service/inventory_sync/restaurant_service.rb
Overview
Service for syncing restaurant inventory from external suppliers (Tablecheck, SevenRooms).
This service encapsulates all business logic for inventory sync, including:
-
Fetching timetables from the supplier via InventoryFetcherService
-
Importing and deleting inventory records in batches with retry logic
-
Triggering reservation workers and cache invalidation
-
Sending inventory events to HH-Search via Kafka
-
Error handling and reporting to APM (APMErrorHandler.report)
-
ElasticAPM instrumentation for tracing and performance monitoring
-
Centralized supplier validation logic via SUPPLIER_CONFIG
Constant Summary
Constants included from SupplierConfig
SupplierConfig::SUPPLIER_CONFIG
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#end_date ⇒ Object
readonly
Returns the value of attribute end_date.
-
#restaurant ⇒ Object
readonly
Returns the value of attribute restaurant.
-
#restaurant_id ⇒ Object
readonly
Returns the value of attribute restaurant_id.
-
#restaurant_tz ⇒ Object
readonly
Returns the value of attribute restaurant_tz.
-
#start_date ⇒ Object
readonly
Returns the value of attribute start_date.
-
#supplier ⇒ Object
readonly
Returns the value of attribute supplier.
Instance Method Summary collapse
-
#call ⇒ Boolean
Main entry point for syncing inventory.
-
#initialize(restaurant_id:, start_date:, end_date:, supplier:) ⇒ RestaurantService
constructor
A new instance of RestaurantService.
Methods included from SupplierConfig
Constructor Details
#initialize(restaurant_id:, start_date:, end_date:, supplier:) ⇒ RestaurantService
Returns a new instance of RestaurantService.
29 30 31 32 33 34 35 36 37 38 |
# File 'app/services/vendors_service/inventory_sync/restaurant_service.rb', line 29 def initialize(restaurant_id:, start_date:, end_date:, supplier:) @restaurant_id = restaurant_id @restaurant = Restaurant.fetch(restaurant_id) @restaurant_tz = Time.find_zone(restaurant.time_zone) @start_date = start_date.to_s @end_date = end_date.to_s @supplier = supplier.to_sym @config = get_supplier_config(supplier, restaurant_id: restaurant_id) validate_supplier_restaurant! end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
27 28 29 |
# File 'app/services/vendors_service/inventory_sync/restaurant_service.rb', line 27 def config @config end |
#end_date ⇒ Object (readonly)
Returns the value of attribute end_date.
27 28 29 |
# File 'app/services/vendors_service/inventory_sync/restaurant_service.rb', line 27 def end_date @end_date end |
#restaurant ⇒ Object (readonly)
Returns the value of attribute restaurant.
27 28 29 |
# File 'app/services/vendors_service/inventory_sync/restaurant_service.rb', line 27 def restaurant @restaurant end |
#restaurant_id ⇒ Object (readonly)
Returns the value of attribute restaurant_id.
27 28 29 |
# File 'app/services/vendors_service/inventory_sync/restaurant_service.rb', line 27 def restaurant_id @restaurant_id end |
#restaurant_tz ⇒ Object (readonly)
Returns the value of attribute restaurant_tz.
27 28 29 |
# File 'app/services/vendors_service/inventory_sync/restaurant_service.rb', line 27 def restaurant_tz @restaurant_tz end |
#start_date ⇒ Object (readonly)
Returns the value of attribute start_date.
27 28 29 |
# File 'app/services/vendors_service/inventory_sync/restaurant_service.rb', line 27 def start_date @start_date end |
#supplier ⇒ Object (readonly)
Returns the value of attribute supplier.
27 28 29 |
# File 'app/services/vendors_service/inventory_sync/restaurant_service.rb', line 27 def supplier @supplier end |
Instance Method Details
#call ⇒ Boolean
Main entry point for syncing inventory.
Performs complete inventory sync including validation, fetching, database operations, and post-sync activities (workers, cache invalidation, HH-Search events).
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/services/vendors_service/inventory_sync/restaurant_service.rb', line 49 def call context_attrs = { restaurant_id: restaurant_id, start_date: start_date, end_date: end_date, supplier: supplier, } start_date_obj = Date.parse(start_date) end_date_obj = Date.parse(end_date) = (start_date, end_date) sync_inventory(, start_date_obj, end_date_obj) true rescue VendorsService::InventorySync::InventoryFetcherService::SupplierApiError, VendorsService::InventorySync::InventoryFetcherService::RateLimitExceededError, StandardError => e = "#{self.class} #{supplier.capitalize}: #{e.}" APMErrorHandler.report(, exception: e, context: context_attrs) raise e end |