From 2e9b402fd7c9b1571bb7fb7fccac3f9ed70724b3 Mon Sep 17 00:00:00 2001 From: David Bayly Date: Tue, 20 Aug 2024 15:12:26 -0600 Subject: [PATCH] Reduced complexity of the new sync function --- apps/api/src/applicant/external-api.service.ts | 15 +++++++++++++++ apps/api/src/syncdata.ts | 15 +-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/apps/api/src/applicant/external-api.service.ts b/apps/api/src/applicant/external-api.service.ts index f793a4f0..4cb86931 100644 --- a/apps/api/src/applicant/external-api.service.ts +++ b/apps/api/src/applicant/external-api.service.ts @@ -778,6 +778,21 @@ export class ExternalAPIService { } } + async slicedSync(from: string, to: string) { + let result: SyncApplicantsResultDTO | undefined; + let page = 1; + let failCount = 0; + do { + try { + result = await this.saveApplicant(from, to, page); + } catch (e) { + this.logger.error(e, `ATS-SYNC Page ${page} failed.`); + failCount++; + } + page = page + 5; + } while ((!result?.done || !!result) && failCount < 5); + } + async getApplicants(filter: IENUserFilterAPIDTO): Promise { const { from, to, limit, skip } = filter; const audits: { applicant_id: string }[] = await this.ienapplicantStatusAuditRepository diff --git a/apps/api/src/syncdata.ts b/apps/api/src/syncdata.ts index 482899a8..4109d369 100644 --- a/apps/api/src/syncdata.ts +++ b/apps/api/src/syncdata.ts @@ -46,20 +46,7 @@ export const handler: Handler = async (event, context: Context) => { page = event.page; } if (process.env.PROTOTYPE_SYNC && !page) { - let result: SyncApplicantsResultDTO | undefined; - if (!page) { - page = 1; - let failCount = 0; - do { - try { - result = await externalAPIService.saveApplicant(from, to, page); - } catch (e) { - logger.error(e, `ATS-SYNC Page ${page} failed.`); - failCount++; - } - page = page + 5; - } while ((!result?.done || !!result) && failCount < 5); - } + await externalAPIService.saveApplicant(from, to); } else { await externalAPIService.saveApplicant(from, to, page); }