Skip to content

Commit 6b91619

Browse files
committed
add timer for cerative mode
1 parent dc48864 commit 6b91619

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/inferred_mode/inferred_mode.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,16 @@ export default class InferredQueryHandler {
523523
[resultID: string]: number;
524524
} = {};
525525

526+
527+
const MAX_TIME = 4.5 * 60 * 1000; // 4 minutes
528+
const QUERY_TIME = 2.5 * 60 * 1000; // 2.5 minutes
529+
const start = Date.now();
530+
526531
await async.eachOfSeries(subQueries, async ({ template, queryGraph }, i) => {
532+
if (Date.now() - start > MAX_TIME - QUERY_TIME) {
533+
debug(`Skipping template because the query has been running for ${(Date.now() - start) / 1000} seconds, and this template is projected to take ${QUERY_TIME / 1000} seconds`);
534+
return;
535+
}
527536
const span = Telemetry.startSpan({ description: 'creativeTemplate' });
528537
span.setData('template', (i as number) + 1);
529538
i = i as number;

0 commit comments

Comments
 (0)