Skip to main content

JodGig Company Sync

Sync Process

we'll schedule the sync job to run DAILY at 11 PM SGT and write it to Gig::SyncLog.

JodGig Company Sync

We'll sync using upsert to ensure that newly created companies are migrated automatically to JodApp's Org::Company. We need to ensure we're not overwriting existing company in JodApp with data from JodGig

Step by step process:

  1. check for newly created company or newly updated company, by comparing last sync date and the JodGig::Company's timestamp
  2. for each created/updated company we will upsert_all on Org::Company, return the newly created/updated Org::Company id using returning params for upsert_all function
  3. map Org::Company to Billing::Account attributes, upsert_all on Billing::Account, return the newly created/updated Billing::Account id + Org::Company id, using returning params for upsert_all function
  4. map Billing::Account and JodGig::Company attributes to Billing::Agreement
  5. Billing Agreement will be created in active record way, so that we ensure that Billing::AgreementTerm can only accessed by Billing::Agreement
  6. asynchronously move file in jodgig AWS bucket which related to contract_service_filename into the path from Billing::Agreement.document_url

Sync Script

...
# remember that JodGig's DB is using naive SGT time for it's datetime fields
updated_companies = JodGig::Company.where(updated_at: last_updated_at.. )

company_upserts = updated_companies.each do | updated_company |
JodGig::Company::AttributeService.execute(jodgig_company: updated_company)
end
Org::Company.upsert_all(
company_upserts,
unique_by: :remote_id,
record_timestamp: true
)

# write to Gig::SyncLog
...
end