Class: SpreeCmCommissioner::Integrations::BookMeBusV1::SyncStrategies::FullSyncStrategy
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Integrations::BookMeBusV1::SyncStrategies::FullSyncStrategy
- Defined in:
- app/services/spree_cm_commissioner/integrations/book_me_bus_v1/sync_strategies/full_sync_strategy.rb
Overview
Full sync strategy - syncs all locations and trips from BookMeBus external system.
Runs on a schedule (e.g., daily at 2:00 AM) to fetch and update all data from BookMeBus API.
Sync Flow
-
**Full Sync** (this strategy) - runs daily at 2:00 AM
-
Sync Locations:
-
Fetches all locations from BookMeBus API
-
Creates/updates Place records with geocoding
-
Creates VendorPlace records (type: :location)
-
Archives stale location mappings
-
-
Sync Routes:
-
Generates route pairs from synced locations
-
Creates Route (origin_place → destination_place) records
-
Creates IntegrationMapping for each route (for incremental sync scheduling)
-
-
Sync Trips (for each route):
-
Fetches trips from BookMeBus search_trips API
-
Creates/updates Trip with: VehicleType, Product, origin/destination places
-
Creates Variant for the Product (ticket type)
-
Creates StockItem with capacity from seats_remaining/number_of_seats
-
Creates TripStops for boarding/drop-off points
-
Creates RouteStops for boarding/drop-off points
-
-
-
**Incremental Sync** (IncrementalSyncStrategy) - runs periodically (e.g., every 10s)
-
Gets oldest route needing sync (by last_synced_at)
-
Syncs trip data for that route only
-
Updates availability (seats_remaining) without full location resync
-
Sellable Ticket Requirements
For a ticket to be sellable, the sync must create:
- Product (product_type: :transit, status: :active)
- Variant (non-master, with price)
- StockItem (links variant to vendor's stock_location with count_on_hand)
- InventoryItem (generated by scheduled PermanentInventoryItemsGeneratorJob)
The InventoryItem is NOT created by sync - it’s generated daily by a scheduled job that creates date-based inventory for permanent stock products (transit, accommodation).
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(integration:, routes: nil) ⇒ FullSyncStrategy
constructor
A new instance of FullSyncStrategy.
Constructor Details
#initialize(integration:, routes: nil) ⇒ FullSyncStrategy
Returns a new instance of FullSyncStrategy.
44 45 46 47 48 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/sync_strategies/full_sync_strategy.rb', line 44 def initialize(integration:, routes: nil) @integration = integration @custom_routes = routes @sync_result = ::SpreeCmCommissioner::Integrations::Base::SyncResult.new end |
Instance Method Details
#call ⇒ Object
50 51 52 53 54 55 56 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/sync_strategies/full_sync_strategy.rb', line 50 def call sync_locations! sync_routes! sync_all_trips! @sync_result end |