Fix native provisioning scheduling and progress reporting
This commit is contained in:
@@ -1,8 +1,17 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { reportHostOperation } from '$lib/server/hosts/index.js';
|
||||
import { authenticateAgent, hostApiError, objectBody } from '$lib/server/hosts/http.js';
|
||||
import { kickProvisioning } from '$lib/server/pipeline/worker.js';
|
||||
export async function POST({ request, params }: { request: Request; params: { id: string } }) {
|
||||
const host = authenticateAgent(request);
|
||||
try { const body = await objectBody(request, 128 * 1024 * 1024); const operation = reportHostOperation(host.id, params.id, { state: body.state, result: body.result, error: body.error }); return json({ operation: { id: operation.id, state: operation.state } }); }
|
||||
try {
|
||||
const body = await objectBody(request, 128 * 1024 * 1024);
|
||||
const operation = reportHostOperation(host.id, params.id, { state: body.state, result: body.result, error: body.error });
|
||||
if (['completed', 'failed', 'unknown'].includes(operation.state)
|
||||
&& (operation.kind.startsWith('instance.') && operation.kind !== 'instance.inspect' || operation.kind === 'files.stage')) {
|
||||
void kickProvisioning().catch(error => console.error('[agent] provisioning wake failed:', error));
|
||||
}
|
||||
return json({ operation: { id: operation.id, state: operation.state } });
|
||||
}
|
||||
catch (cause) { return hostApiError(cause); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user