feat: add Watchdog recovery and drift rebuild workflows
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { DriftPlanChanged, previewDrift, runDriftDeployment } from '$lib/server/fleet/drift.js';
|
||||
import { kick } from '$lib/server/pipeline/worker.js';
|
||||
import { previewDrift } from '$lib/server/fleet/drift.js';
|
||||
|
||||
// GET returns the current drift plan for the whole fleet without touching disk.
|
||||
export async function GET() {
|
||||
@@ -27,7 +26,7 @@ export async function GET() {
|
||||
});
|
||||
}
|
||||
|
||||
// POST removes drift and creates a drift deployment. Body: { servers?: string[], dryRun?: boolean }
|
||||
// Legacy previews remain readable. Watchdog owns all new reconciliation requests.
|
||||
export async function POST({ request }: { request: Request }) {
|
||||
const body = await request.json().catch(() => null);
|
||||
if (!body || (body.servers !== undefined && (!Array.isArray(body.servers) || !body.servers.every((server: unknown) => typeof server === 'string')))) {
|
||||
@@ -35,12 +34,8 @@ export async function POST({ request }: { request: Request }) {
|
||||
}
|
||||
try {
|
||||
if (body.dryRun === true) return json({ ok: true, plan: await previewDrift(body.servers) });
|
||||
if (typeof body.expectedFingerprint !== 'string' || !body.expectedFingerprint) return json({ ok: false, error: 'Review a reconciliation plan before applying changes.' }, { status: 400 });
|
||||
const result = await runDriftDeployment({ servers: body.servers, expectedFingerprint: body.expectedFingerprint, triggeredBy: 'ui' });
|
||||
if (result.deploymentId) void kick();
|
||||
return json({ ok: true, result });
|
||||
return json({ ok: false, error: 'Drift reconciliation has moved to Watchdog. Scan there to queue a rebuild and campaign.', watchdogUrl: '/watchdog' }, { status: 410 });
|
||||
} catch (error) {
|
||||
if (error instanceof DriftPlanChanged) return json({ ok: false, error: error.message, plan: error.plan }, { status: 409 });
|
||||
return json({ ok: false, error: (error as Error).message }, { status: 400 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user