JodGig Company Sync
Sync Process
we'll schedule the sync job to run DAILY at 11 PM SGT and write it to Gig::SyncLog.
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:
- check for newly created company or newly updated company, by comparing last sync date and the
JodGig::Company's timestamp - for each created/updated company we will upsert_all on
Org::Company, return the newly created/updatedOrg::Companyidusingreturningparams forupsert_allfunction - map Org::Company to
Billing::Accountattributes, upsert_all onBilling::Account, return the newly created/updatedBilling::Accountid+Org::Companyid, usingreturningparams forupsert_allfunction - map Billing::Account and JodGig::Company attributes to
Billing::Agreement - Billing Agreement will be created in active record way, so that we ensure that
Billing::AgreementTermcan only accessed byBilling::Agreement - asynchronously move file in jodgig AWS bucket which related to
contract_service_filenameinto the path fromBilling::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