Skip to content

Commit

Permalink
creative timeout environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
rjawesome committed Jun 26, 2024
1 parent 3ce0b79 commit 1203b2c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/inferred_mode/inferred_mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default class InferredQueryHandler {
predicatePath: string;
includeReasoner: boolean;
CREATIVE_LIMIT: number;
CREATIVE_TIMEOUT: number;
constructor(
parent: TRAPIQueryHandler,
queryGraph: TrapiQueryGraph,
Expand All @@ -69,6 +70,7 @@ export default class InferredQueryHandler {
this.predicatePath = predicatePath;
this.includeReasoner = includeReasoner;
this.CREATIVE_LIMIT = process.env.CREATIVE_LIMIT ? parseInt(process.env.CREATIVE_LIMIT) : 500;
this.CREATIVE_TIMEOUT = process.env.CREATIVE_TIMEOUT_S ? parseInt(process.env.CREATIVE_TIMEOUT) * 1000 : 4.8 * 60 * 1000;
}

get queryIsValid(): boolean {
Expand Down Expand Up @@ -518,16 +520,14 @@ export default class InferredQueryHandler {
[resultID: string]: number;
} = {};

const QUERY_TIMEOUT = 4.8 * 60 * 1000; // 4.5 minutes

const completedHandlers = await Promise.all(
subQueries.map(async ({ template, queryGraph }, i) => {
const span = Telemetry.startSpan({ description: 'creativeTemplate' });
span.setData('template', i + 1);
const handler = new TRAPIQueryHandler(this.options, this.path, this.predicatePath, this.includeReasoner);
handler.setQueryGraph(queryGraph);
try {
await timeoutPromise(handler.query(AbortSignal.timeout(QUERY_TIMEOUT)), QUERY_TIMEOUT);
await timeoutPromise(handler.query(AbortSignal.timeout(this.CREATIVE_TIMEOUT)), this.CREATIVE_TIMEOUT);
} catch (error) {
handler.logs.forEach((log) => {
combinedResponse.logs.push(log);
Expand Down

0 comments on commit 1203b2c

Please sign in to comment.