Class: SpreeCmCommissioner::Integrations::BookMeBusV1::SyncStrategies::IncrementalSyncStrategy

Inherits:
Object
  • Object
show all
Defined in:
app/services/spree_cm_commissioner/integrations/book_me_bus_v1/sync_strategies/incremental_sync_strategy.rb

Overview

Incremental sync strategy - syncs trip data for specific routes.

Runs periodically to fetch updated trip information for active routes. This allows keeping trip availability fresh without re-syncing all locations.

Flow:

1. Gets the next vendor_route needing sync (oldest last_synced_at)
2. Gets the route's direction mapping to find origin_id/destination_id
3. Calls search_trips API and syncs trip data
4. Updates route mapping's last_synced_at

Instance Method Summary collapse

Constructor Details

#initialize(integration:) ⇒ IncrementalSyncStrategy

Returns a new instance of IncrementalSyncStrategy.



14
15
16
17
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/sync_strategies/incremental_sync_strategy.rb', line 14

def initialize(integration:)
  @integration = integration
  @sync_result = ::SpreeCmCommissioner::Integrations::Base::SyncResult.new
end

Instance Method Details

#callObject



19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/sync_strategies/incremental_sync_strategy.rb', line 19

def call
  vendor_route = find_next_vendor_route_to_sync
  return @sync_result unless vendor_route

  sync_trips_for_vendor_route!(vendor_route)

  @sync_result
rescue StandardError => e
  @sync_result.record_error(e)
  @sync_result
end