Class: Kidspire::PcoOutboundRegistrationSyncJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/kidspire/pco_outbound_registration_sync_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(registration_id) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/jobs/kidspire/pco_outbound_registration_sync_job.rb', line 3

def perform(registration_id)
  registration = Registration.includes(:family, :child, :event).find(registration_id)
  family       = registration.family
  child        = registration.child
  event        = registration.event

  return unless family.pco_sync_enabled?
  return unless SyncSetting.current.outbound_registrations_sync?
  return if registration.synced_to_pco?

  unless child.pco_person_id.present? && event.pco_event_id.present?
    Rails.logger.info(
      "[Kidspire] PcoOutboundRegistrationSyncJob skipped for registration #{registration_id} " \
      "— child or event not linked to PCO"
    )
    return
  end

  client = PcoClient.new

  if event.pco_source == "check_ins"
    sync_as_checkin(client, registration, child, event)
  else
    Rails.logger.info(
      "[Kidspire] PcoOutboundRegistrationSyncJob: calendar event #{event.pco_event_id}" \
      "PCO Registrations API not implemented in v1, marking synced"
    )
  end

  registration.update_columns(synced_to_pco: true, pco_synced_at: Time.current)
  Rails.logger.info("[Kidspire] PcoOutboundRegistrationSyncJob complete for registration #{registration_id}")
rescue ActiveRecord::RecordNotFound
  Rails.logger.warn("[Kidspire] PcoOutboundRegistrationSyncJob: registration #{registration_id} not found, discarding")
rescue PcoError => e
  Rails.logger.error("[Kidspire] PcoOutboundRegistrationSyncJob failed for registration #{registration_id}: #{e.message}")
  raise
end