Skip to content

Commit df99cb0

Browse files
committed
run webhook ingestion in background to avoid timeout
1 parent 9acdda0 commit df99cb0

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

mimir-rag/src/server/routes/ingest.ts

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,41 @@ async function triggerIngestion(
3737
context.setIngestionBusy(true);
3838
const startedAt = Date.now();
3939

40-
try {
41-
logger.info({ trigger }, "Starting ingestion.");
42-
const result = await runIngestionPipeline(context.config, context.llm, context.store, logger);
43-
res.json({
44-
status: "ok",
40+
const isWebhook = trigger.startsWith('github-webhook');
41+
42+
if (isWebhook) {
43+
res.status(202).json({
44+
status: "accepted",
45+
message: "Ingestion started in background.",
4546
trigger,
46-
durationMs: Date.now() - startedAt,
47-
stats: result.stats,
4847
});
49-
} catch (error) {
50-
logger.error({ err: error, trigger }, "Ingestion failed.");
51-
res.status(500).json({ status: "error", message: (error as Error).message });
52-
} finally {
53-
context.setIngestionBusy(false);
48+
49+
runIngestionPipeline(context.config, context.llm, context.store, logger)
50+
.then((result) => {
51+
logger.info({ trigger, durationMs: Date.now() - startedAt, stats: result.stats }, "Ingestion completed.");
52+
})
53+
.catch((error) => {
54+
logger.error({ err: error, trigger }, "Ingestion failed.");
55+
})
56+
.finally(() => {
57+
context.setIngestionBusy(false);
58+
});
59+
} else {
60+
try {
61+
logger.info({ trigger }, "Starting ingestion.");
62+
const result = await runIngestionPipeline(context.config, context.llm, context.store, logger);
63+
res.json({
64+
status: "ok",
65+
trigger,
66+
durationMs: Date.now() - startedAt,
67+
stats: result.stats,
68+
});
69+
} catch (error) {
70+
logger.error({ err: error, trigger }, "Ingestion failed.");
71+
res.status(500).json({ status: "error", message: (error as Error).message });
72+
} finally {
73+
context.setIngestionBusy(false);
74+
}
5475
}
5576
}
5677

0 commit comments

Comments
 (0)