fix: add try-catch on agents.invoke and http.fetch in scheduled jobs
- stale-case-reminder: wrap http.fetch in try-catch so network errors log and return instead of crashing the job silently - weekly-feedback-analysis: wrap agents.invoke in try-catch so CEO unavailability logs and returns instead of crashing the job Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -713,7 +713,15 @@ const plugin = definePlugin({
|
|||||||
const apiBase =
|
const apiBase =
|
||||||
(config.legalApiBaseUrl as string) ?? "http://localhost:8085";
|
(config.legalApiBaseUrl as string) ?? "http://localhost:8085";
|
||||||
|
|
||||||
const resp = await ctx.http.fetch(`${apiBase}/api/cases/stale?days=3`);
|
let resp: Awaited<ReturnType<typeof ctx.http.fetch>>;
|
||||||
|
try {
|
||||||
|
resp = await ctx.http.fetch(`${apiBase}/api/cases/stale?days=3`);
|
||||||
|
} catch (err) {
|
||||||
|
ctx.logger.error("stale-case-reminder: fetch failed", {
|
||||||
|
error: String(err),
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!resp.ok) {
|
if (!resp.ok) {
|
||||||
ctx.logger.error(`stale-case-reminder: API error ${resp.status}`);
|
ctx.logger.error(`stale-case-reminder: API error ${resp.status}`);
|
||||||
return;
|
return;
|
||||||
@@ -817,14 +825,21 @@ const plugin = definePlugin({
|
|||||||
|
|
||||||
const { company, ceoId } = mapped[0];
|
const { company, ceoId } = mapped[0];
|
||||||
|
|
||||||
|
try {
|
||||||
await ctx.agents.invoke(ceoId, company.id, {
|
await ctx.agents.invoke(ceoId, company.id, {
|
||||||
prompt: `ניתוח פידבק שבועי יו"ר (${data.entry_count} פריטים):\n\n${data.summary}\n\nהמשימה: עדכן את /home/chaim/legal-ai/docs/legal-decision-lessons.md עם הלקחים החדשים שעולים מהפידבק. הוסף רק לקחים חדשים שלא קיימים כבר. קבץ לפי נושא.`,
|
prompt: `ניתוח פידבק שבועי יו"ר (${data.entry_count} פריטים):\n\n${data.summary}\n\nהמשימה: עדכן את /home/chaim/legal-ai/docs/legal-decision-lessons.md עם הלקחים החדשים שעולים מהפידבק. הוסף רק לקחים חדשים שלא קיימים כבר. קבץ לפי נושא.`,
|
||||||
reason: "weekly-feedback-job",
|
reason: "weekly-feedback-job",
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.logger.info(
|
ctx.logger.info(
|
||||||
`weekly-feedback-analysis: invoked CEO ${ceoId} (company ${company.id}) with ${data.entry_count} feedback entries`,
|
`weekly-feedback-analysis: invoked CEO ${ceoId} (company ${company.id}) with ${data.entry_count} feedback entries`,
|
||||||
);
|
);
|
||||||
|
} catch (err) {
|
||||||
|
ctx.logger.error("weekly-feedback-analysis: failed to invoke CEO", {
|
||||||
|
error: String(err),
|
||||||
|
ceoId,
|
||||||
|
companyId: company.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.logger.info("Legal AI plugin ready");
|
ctx.logger.info("Legal AI plugin ready");
|
||||||
|
|||||||
Reference in New Issue
Block a user