Class: Keinaufwand::Sync::SyncService

Inherits:
Object
  • Object
show all
Defined in:
lib/keinaufwand/sync_core/sync_service.rb

Constant Summary collapse

DEFAULT_RESOURCES =
%w[
  Location Product Session EventDetail Event Post InstructorGroup
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(client:, record_class:, sync_state_class:, resources: DEFAULT_RESOURCES, asset_class: nil, receipt_class: nil, output: nil) ⇒ SyncService

Returns a new instance of SyncService.



8
9
10
11
12
13
14
15
16
# File 'lib/keinaufwand/sync_core/sync_service.rb', line 8

def initialize(client:, record_class:, sync_state_class:, resources: DEFAULT_RESOURCES, asset_class: nil, receipt_class: nil, output: nil)
  @client = client
  @record_class = record_class
  @sync_state_class = sync_state_class
  @resources = resources
  @asset_class = asset_class
  @receipt_class = receipt_class
  @output = output
end

Instance Method Details

#performObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/keinaufwand/sync_core/sync_service.rb', line 18

def perform
  started = monotonic_time
  succeeded = 0
  log "Starting Keinaufwand Sync (#{@resources.size} resources)"
  @resources.each_with_index do |resource, index|
    begin
      sync_resource(resource, index + 1)
      succeeded += 1
    rescue StandardError => error
      log "!! FAILED #{resource}: #{error.message}"
      log "Sync stopped (#{succeeded}/#{@resources.size} succeeded)"
      raise
    end
  end
  log "Sync Process Completed in #{format('%.2f', monotonic_time - started)}s (#{succeeded}/#{@resources.size} succeeded)"
end