Migrate instances when draining and verify hosts before enabling
This commit is contained in:
@@ -5,6 +5,8 @@ import { hostApiError, objectBody, requireManagementOrigin } from '$lib/server/h
|
||||
import { presentHostPreparation } from '$lib/server/hosts/preparation.js';
|
||||
import { config } from '$lib/server/config.js';
|
||||
import { hostInstances } from '$lib/server/hosts/instances.js';
|
||||
import { reconcileHostPreparation } from '$lib/server/hosts/preparation.js';
|
||||
import { kickProvisioning } from '$lib/server/pipeline/worker.js';
|
||||
type Event = { request: Request; params: { id: string } };
|
||||
export function GET({ request, params }: Event) {
|
||||
requireManagementOrigin(request); const host = getHost(params.id); if (!host) error(404, 'Host not found.');
|
||||
@@ -12,7 +14,14 @@ export function GET({ request, params }: Event) {
|
||||
}
|
||||
export async function PATCH({ request, params }: Event) {
|
||||
requireManagementOrigin(request);
|
||||
try { return json({ host: updateHost(params.id, await objectBody(request)) }); } catch (cause) { return hostApiError(cause); }
|
||||
try {
|
||||
const body = await objectBody(request);
|
||||
if (body.mode !== undefined && body.mode !== 'active' && body.mode !== 'draining') throw new Error('Choose Enable or Drain host. Hosts disable automatically after draining.');
|
||||
updateHost(params.id, body);
|
||||
if (body.mode === 'active') reconcileHostPreparation(params.id);
|
||||
if (body.mode === 'draining') void kickProvisioning().catch(cause => console.error('[host-drain]', cause));
|
||||
return json({ host: presentHostPreparation(getHost(params.id)!) });
|
||||
} catch (cause) { return hostApiError(cause); }
|
||||
}
|
||||
|
||||
export function DELETE({ request, params }: Event) {
|
||||
|
||||
Reference in New Issue
Block a user