Module: VendorsService::InventorySync::SupplierConfig

Included in:
InventoryFetcherService, ReservationService, RestaurantService, SchedulerService
Defined in:
app/services/vendors_service/inventory_sync/supplier_config.rb

Overview

Shared configuration constants for all inventory sync suppliers. Centralizes supplier-specific settings used across InventoryFetcherService and RestaurantService.

Constant Summary collapse

SUPPLIER_CONFIG =

Main supplier configuration with service classes, validation logic, and API settings

{
  tablecheck: {
    validator: ->(restaurant) { restaurant&.inventory_tablecheck? },
    min_seat_method: ->(restaurant) { restaurant&.tablecheck_restaurant&.min_seat.to_i },
    inv_service: Tablecheck::Availabilities::Timetable,
    sync_worker_class: Vendors::Tablecheck::RestaurantInventorySyncWorker,
    sync_trigger_model: Tablecheck::InvSyncTrigger,
    reservation_inv_mismatch_model: Tablecheck::ReservationInvMismatch,
    flipper_feature: :tablecheck,
    restaurant_association: :tablecheck_restaurant,
    shop_id_field: :shop_id,
    rate_limit_cooldown_seconds: 5 * 60, # 10,000 requests / 5 minutes
    max_availability_days_per_request: 7, # Tablecheck returns up to 7 days availability per request
    sync_batch_size: 75, # 10,000/130 where 130 => (180/7)*5 api calls per restaurant for 180 days timeslots with retry 5 partysizes
    sync_delay_interval: 5.minutes,
    inv_mismatch_sync_delay_interval: 10.minutes,
  },
  bistrochat: {
    validator: ->(restaurant) { restaurant&.inventory_bistrochat? },
    min_seat_method: ->(restaurant) { restaurant&.bistrochat_restaurant&.min_seat.to_i },
    inv_service: Bistrochat::Availabilities::Timetable,
    sync_worker_class: Vendors::Bistrochat::RestaurantInventorySyncWorker,
    sync_trigger_model: Bistrochat::InvSyncTrigger,
    reservation_inv_mismatch_model: Bistrochat::ReservationInvMismatch,
    flipper_feature: :bistrochat,
    restaurant_association: :bistrochat_restaurant,
    shop_id_field: :shop_id,
    rate_limit_cooldown_seconds: 100, # 5000 requests / 100 seconds
    max_availability_days_per_request: 7, # Bistrochat returns up to 7 days availability per request
    sync_batch_size: 38, # 5000/130 where 130 => (180/7)*5 api calls per restaurant for 180 days timeslots with retry 5 partysizes
    sync_delay_interval: 100.seconds,
    inv_mismatch_sync_delay_interval: 10.minutes,
  },
  sevenrooms: {
    validator: ->(restaurant) { restaurant&.inventory_seven_rooms? },
    min_seat_method: ->(restaurant) { restaurant&.seven_rooms_restaurant&.min_seat.to_i },
    inv_service: SevenRooms::Availabilities::Availability,
    sync_worker_class: Vendors::SevenRooms::RestaurantInventorySyncWorker,
    sync_trigger_model: SevenRooms::InvSyncTrigger,
    reservation_inv_mismatch_model: SevenRooms::ReservationInvMismatch,
    flipper_feature: :seven_rooms,
    restaurant_association: :seven_rooms_restaurant,
    shop_id_field: :venue_id,
    rate_limit_cooldown_seconds: 10, # 1000 requests / 10 seconds
    max_availability_days_per_request: 1, # sevenrooms returns single date availability per request
    sync_batch_size: 1, # 1000/900 where 900 => (180/1)*5 api calls per restaurant for 180 days timeslots with retry 5 partysizes
    sync_delay_interval: 10.seconds,
    inv_mismatch_sync_delay_interval: 10.minutes,
  },
  mymenu: {
    validator: ->(restaurant) { restaurant&.inventory_my_menu? },
    min_seat_method: ->(restaurant) { restaurant&.my_menu_restaurant&.min_seat.to_i },
    inv_service: MyMenu::Availabilities::Timetable,
    sync_worker_class: Vendors::MyMenu::RestaurantInventorySyncWorker,
    sync_trigger_model: MyMenu::InvSyncTrigger,
    reservation_inv_mismatch_model: MyMenu::ReservationInvMismatch,
    flipper_feature: :mymenu,
    restaurant_association: :my_menu_restaurant,
    shop_id_field: :shop_id,
    rate_limit_cooldown_seconds: 100, # 5000 requests / 100 seconds
    max_availability_days_per_request: 7, # MyMenu returns up to 7 days availability per request
    sync_batch_size: 38, # 5000/130 where 130 => (180/7)*5 api calls per restaurant for 180 days timeslots with retry 5 partysizes
    sync_delay_interval: 100.seconds,
    inv_mismatch_sync_delay_interval: 10.minutes,
  },
}.freeze

Instance Method Summary collapse

Instance Method Details

#get_supplier_config(supplier, context = {}) ⇒ Hash

Gets supplier configuration and validates that the supplier is supported. Uses SUPPLIER_CONFIG.key? for validation and raises NotImplementedError for unknown suppliers.

Parameters:

  • supplier (Symbol)

    The supplier to get config for

  • context (Hash) (defaults to: {})

    Additional context for APM reporting

Returns:

  • (Hash)

    Supplier configuration hash

Raises:

  • (NotImplementedError)

    if supplier is not supported



82
83
84
85
86
87
88
89
90
# File 'app/services/vendors_service/inventory_sync/supplier_config.rb', line 82

def get_supplier_config(supplier, context = {})
  if SUPPLIER_CONFIG.key?(supplier)
    SUPPLIER_CONFIG[supplier]
  else
    error_message = "VendorsService::InventorySync: Unknown supplier: #{supplier}"
    APMErrorHandler.report(error_message, context: context.merge(supplier: supplier))
    raise NotImplementedError, error_message
  end
end