Skip to content

Commit

Permalink
fix: pfocr server selection, timeout handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tokebe committed Aug 9, 2024
1 parent 29bab45 commit 2d754fe
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions src/results_assembly/pfocr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,19 @@ async function getAllByScrolling(
hits: RawFigureResult[] = [],
): Promise<RawFigureResult[]> {
queryBody.from = batchIndex;
const { data } = await axios.post(baseUrl, queryBody).catch((err) => {
debug('Error in scrolling request', err);
throw err;
});
let data: { hits: RawFigureResult[]; max_total: number };
try {
data = (await axios.post(baseUrl, queryBody, { timeout: 15000 })).data;
} catch (err) {
debug(`Error in scrolling request window ${batchIndex}-${batchIndex + 1000}, error is ${(err as Error).message}`);
}

if (data) {
hits.push(...data.hits);
debug(`Batch window ${batchIndex}-${batchIndex + 1000}: ${data.hits.length} hits retrieved for PFOCR figure data`);
}

hits.push(...data.hits);
debug(`Batch window ${batchIndex}-${batchIndex + 1000}: ${data.hits.length} hits retrieved for PFOCR figure data`);
if (batchIndex + 1000 < data.max_total) {
if (data && batchIndex + 1000 < data.max_total) {
return await getAllByScrolling(baseUrl, queryBody, batchIndex + 1000, hits);
} else {
return hits;
Expand All @@ -82,7 +87,12 @@ async function getAllByScrolling(
*/
async function getPfocrFigures(qTerms: Set<string>): Promise<DeDupedFigureResult[]> {
debug(`Getting PFOCR figure data`);
const url = 'https://biothings.ncats.io/pfocr/query';
const url = {
dev: 'https://biothings.ci.transltr.io/pfocr/query',
ci: 'https://biothings.ci.transltr.io/pfocr/query',
test: 'https://biothings.test.transltr.io/pfocr/query',
prod: 'https://biothings.ncats.io/pfocr/query',
}[process.env.INSTANCE_ENV ?? 'prod'];
/*
* We can now POST using minimum_should_match to bypass most set logic on our side
* detailed here: https://github.com/biothings/pending.api/issues/88
Expand Down Expand Up @@ -212,10 +222,16 @@ export async function enrichTrapiResultsWithPfocrFigures(response: TrapiResponse

let figures: DeDupedFigureResult[];
try {
figures = await getPfocrFigures(curieCombos)
figures = await getPfocrFigures(curieCombos);
} catch (err) {
debug('Error getting PFOCR figures (enrichTrapiResultsWithPfocrFigures)', err);
logs.push(new LogEntry('ERROR', null, 'Error getting PFOCR figures, results will not be enriched.').getLog())
debug('Error getting PFOCR figures (enrichTrapiResultsWithPfocrFigures)', (err as Error).message);
logs.push(
new LogEntry(
'WARNING',
null,
`Error getting PFOCR figures, results will not be enriched. The error is ${err.message}`,
).getLog(),
);
}
if (!figures) return logs;

Expand Down

0 comments on commit 2d754fe

Please sign in to comment.