Fix Telegram worker: countdown timer, orphaned runs, fetch-listener reconnection, and logging

Co-authored-by: xCyanGrizzly <53275238+xCyanGrizzly@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-03-05 20:21:18 +00:00
parent 1436b630e2
commit 71a2e6a5e8
8 changed files with 147 additions and 53 deletions

View File

@@ -45,33 +45,20 @@ export async function POST(request: Request) {
);
}
// Create ingestion runs marked as RUNNING — the worker will pick these up
// when it next polls, or we use pg_notify for immediate pickup
for (const account of accounts) {
// Only create if no run is already RUNNING for this account
const existing = await prisma.ingestionRun.findFirst({
where: { accountId: account.id, status: "RUNNING" },
});
if (!existing) {
await prisma.ingestionRun.create({
data: { accountId: account.id, status: "RUNNING" },
});
}
}
// Send pg_notify for immediate worker pickup
// Send pg_notify for immediate worker pickup.
// The worker creates its own IngestionRun records with proper activity tracking.
try {
await prisma.$queryRawUnsafe(
`SELECT pg_notify('ingestion_trigger', $1)`,
accounts.map((a) => a.id).join(",")
);
} catch {
// pg_notify is best-effort — worker will pick up on next cycle anyway
// pg_notify is best-effort — worker will pick up on next scheduled cycle anyway
}
return NextResponse.json({
triggered: true,
accountIds: accounts.map((a) => a.id),
message: `Ingestion queued for ${accounts.length} account(s)`,
message: `Ingestion triggered for ${accounts.length} account(s)`,
});
}