Skip to content

Commit

Permalink
Reduced complexity of the new sync function
Browse files Browse the repository at this point in the history
  • Loading branch information
dbayly-freshworks committed Aug 20, 2024
1 parent b30a683 commit 2e9b402
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
15 changes: 15 additions & 0 deletions apps/api/src/applicant/external-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ApplicantSyncRO[]> {
const { from, to, limit, skip } = filter;
const audits: { applicant_id: string }[] = await this.ienapplicantStatusAuditRepository
Expand Down
15 changes: 1 addition & 14 deletions apps/api/src/syncdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 2e9b402

Please sign in to comment.