Skip to content

Commit 229c9f9

Browse files
committed
fix(dashboard-agent): restore scheduled maintenance tasks
1 parent 8f51ef1 commit 229c9f9

3 files changed

Lines changed: 55 additions & 3 deletions

File tree

internal-packages/dashboard-agent/src/investigation-sweep.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import {
99
type SettledInvestigation,
1010
type SettledInvestigationCard,
1111
} from "@internal/dashboard-agent-db";
12-
import { logger } from "@trigger.dev/sdk";
12+
import { logger, schedules } from "@trigger.dev/sdk";
1313
import { serializeError } from "./serialize-error";
14+
import { getWatchDb, watchConnectionString } from "./watch-task-adapters";
1415

1516
/**
1617
* The investigation backstop, for cards left `in_progress`. They settle as `inconclusive`,
@@ -171,3 +172,33 @@ export async function sweepDashboardAgentInvestigations(
171172

172173
return result;
173174
}
175+
176+
const EMPTY_SWEEP_RESULT: InvestigationSweepResult = {
177+
stale: 0,
178+
settled: 0,
179+
closed: 0,
180+
alreadySettled: 0,
181+
abandoned: 0,
182+
failed: 0,
183+
};
184+
185+
export const dashboardAgentInvestigationSweep = schedules.task({
186+
id: "dashboard-agent-investigation-sweep",
187+
cron: "*/5 * * * *",
188+
retry: { maxAttempts: 3 },
189+
run: async (): Promise<InvestigationSweepResult> => {
190+
if (!watchConnectionString()) {
191+
logger.warn(
192+
"dashboard-agent investigation sweep skipped: no DASHBOARD_AGENT_DATABASE_URL or DATABASE_URL"
193+
);
194+
return { ...EMPTY_SWEEP_RESULT };
195+
}
196+
197+
const { db } = getWatchDb();
198+
const result = await sweepDashboardAgentInvestigations(db);
199+
200+
logger.info("dashboard-agent investigations swept", result);
201+
202+
return result;
203+
},
204+
});

internal-packages/dashboard-agent/src/maintenance.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import {
55
hardDeleteChatsSoftDeletedBefore,
66
type DashboardAgentDb,
77
} from "@internal/dashboard-agent-db";
8-
import { logger } from "@trigger.dev/sdk";
8+
import { logger, schedules } from "@trigger.dev/sdk";
99
import { serializeError } from "./serialize-error";
10+
import { getWatchDb, watchConnectionString } from "./watch-task-adapters";
1011

1112
/**
1213
* Retention for the agent's own datastore: judged turns, soft-deleted chats, and the
@@ -113,3 +114,23 @@ export async function runDashboardAgentRetention(
113114

114115
return result;
115116
}
117+
118+
export const dashboardAgentMaintenance = schedules.task({
119+
id: "dashboard-agent-maintenance",
120+
cron: "0 3 * * *",
121+
retry: { maxAttempts: 3 },
122+
run: async (): Promise<RetentionResult | undefined> => {
123+
if (!watchConnectionString()) {
124+
logger.warn(
125+
"dashboard-agent maintenance skipped: no DASHBOARD_AGENT_DATABASE_URL or DATABASE_URL"
126+
);
127+
return undefined;
128+
}
129+
130+
const { db } = getWatchDb();
131+
132+
const result = await runDashboardAgentRetention(db);
133+
logger.info("dashboard-agent retention swept", result);
134+
return result;
135+
},
136+
});

knip.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"ignoreDependencies": ["@sentry/cli", "assert", "util"]
2727
},
2828
"internal-packages/dashboard-agent": {
29-
"entry": ["trigger.config.ts"],
29+
"entry": ["trigger.config.ts", "src/investigation-sweep.ts", "src/maintenance.ts"],
3030
"ignoreBinaries": ["rg"]
3131
},
3232
"internal-packages/emails": {

0 commit comments

Comments
 (0)