feat: add Watchdog recovery and drift rebuild workflows
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { watchdogOverview, watchdogTick, setWatchdogEnabled } from '$lib/server/watchdog/index.js';
|
||||
import { kick } from '$lib/server/pipeline/worker.js';
|
||||
|
||||
export function GET() { return json(watchdogOverview()); }
|
||||
export async function POST({ request }: { request: Request }) {
|
||||
const body = await request.json().catch(() => null);
|
||||
if (!body || typeof body !== 'object' || Array.isArray(body)
|
||||
|| (body.enabled !== undefined && typeof body.enabled !== 'boolean')
|
||||
|| (body.action !== 'scan' && typeof body.enabled !== 'boolean')
|
||||
|| (body.action !== undefined && body.action !== 'scan')) {
|
||||
return json({ error: 'Provide action: scan or an enabled boolean.' }, { status: 400 });
|
||||
}
|
||||
if (typeof body.enabled === 'boolean') setWatchdogEnabled(body.enabled);
|
||||
if (body.action === 'scan') await watchdogTick(true);
|
||||
void kick().catch(err => console.error('[watchdog] worker kick failed:', err));
|
||||
return json(watchdogOverview());
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { watchdogDetail, updateWatchdogIncident } from '$lib/server/watchdog/index.js';
|
||||
import { kick } from '$lib/server/pipeline/worker.js';
|
||||
|
||||
export function GET({ params }: { params: { id: string } }) {
|
||||
const detail = watchdogDetail(params.id);
|
||||
return detail ? json(detail) : json({ error: 'Watchdog incident not found.' }, { status: 404 });
|
||||
}
|
||||
export async function POST({ params, request }: { params: { id: string }; request: Request }) {
|
||||
const body = await request.json().catch(() => null);
|
||||
if (!body || !['retry','dismiss'].includes(body.action)) return json({ error: 'Choose retry or dismiss.' }, { status: 400 });
|
||||
const result = updateWatchdogIncident(params.id, body.action);
|
||||
if (!result.ok) return json({ error: result.error }, { status: result.status });
|
||||
void kick().catch(err => console.error('[watchdog] worker kick failed:', err));
|
||||
return json(watchdogDetail(params.id));
|
||||
}
|
||||
Reference in New Issue
Block a user