Class: Kidsmin::PcoOutboundProfileSyncJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/kidsmin/pco_outbound_profile_sync_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(family_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
# File 'app/jobs/kidsmin/pco_outbound_profile_sync_job.rb', line 3

def perform(family_id)
  family = Family.find(family_id)

  return unless family.pco_sync_enabled?
  return unless SyncSetting.current.outbound_people_sync?
  return if family.pco_person_id.blank?  # v1: only update existing PCO people

  client = PcoClient.new

  client.patch("/people/v2/people/#{family.pco_person_id}", {
    data: {
      type:       "Person",
      id:         family.pco_person_id,
      attributes: pco_attributes(family)
    }
  })

  family.update_column(:pco_last_synced_at, Time.current)
  Rails.logger.info("[Kidsmin] PcoOutboundProfileSyncJob complete for family #{family_id}")
rescue ActiveRecord::RecordNotFound
  Rails.logger.warn("[Kidsmin] PcoOutboundProfileSyncJob: family #{family_id} not found, discarding")
rescue PcoError => e
  Rails.logger.error("[Kidsmin] PcoOutboundProfileSyncJob failed for family #{family_id}: #{e.message}")
  raise
end