Class: SpreeCmCommissioner::Integrations::StadiumXV1::SyncStrategies::IncrementalSyncStrategy
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Integrations::StadiumXV1::SyncStrategies::IncrementalSyncStrategy
- Defined in:
- app/services/spree_cm_commissioner/integrations/stadium_x_v1/sync_strategies/incremental_sync_strategy.rb
Overview
Incremental sync strategy - syncs zones one match at a time.
Runs every 10 seconds to sync zone data incrementally. Instead of syncing all matches at once (which would be slow), we sync one match per interval in round-robin order.
Example with 3 matches:
10:00:00 - Sync zones for Match #1 (oldest last_synced_at)
10:00:10 - Sync zones for Match #2
10:00:20 - Sync zones for Match #3
10:00:30 - Sync zones for Match #1 again (cycle repeats)
This ensures all matches get synced regularly without overwhelming the system.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(client:, integration:) ⇒ IncrementalSyncStrategy
constructor
A new instance of IncrementalSyncStrategy.
Constructor Details
#initialize(client:, integration:) ⇒ IncrementalSyncStrategy
Returns a new instance of IncrementalSyncStrategy.
16 17 18 19 20 |
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/sync_strategies/incremental_sync_strategy.rb', line 16 def initialize(client:, integration:) @client = client @integration = integration @sync_result = ::SpreeCmCommissioner::Integrations::Base::SyncResult.new end |
Instance Method Details
#call ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/services/spree_cm_commissioner/integrations/stadium_x_v1/sync_strategies/incremental_sync_strategy.rb', line 22 def call begin oldest_sync_mapping = Spree::Taxon.find_oldest_active_mapping(integration_id: @integration.id) return @sync_result if oldest_sync_mapping.nil? @sync_result.increment_metric(:match, :synced) Polling::SyncZones.new( integration: @integration, client: @integration.client, sync_result: @sync_result ).call(external_match_id: oldest_sync_mapping.external_id) oldest_sync_mapping.update!(last_synced_at: Time.current) rescue StandardError => e @sync_result.record_error(e) end @sync_result end |