Improve application responsiveness and background processing

This commit is contained in:
2026-10-04 19:56:06 -04:00
parent 1392a082da
commit ed004ddbcf
70 changed files with 1324 additions and 345 deletions
+12 -1
View File
@@ -3,6 +3,8 @@ import { migrate } from '$lib/server/db/migrate.js';
import { startWorker } from '$lib/server/pipeline/worker.js';
import { interruptDeployments } from '$lib/server/provisioning/history.js';
import { authenticationHandle } from '$lib/server/auth/guard.js';
import { emit } from '$lib/server/pipeline/bus.js';
import { startPerformanceMonitor } from '$lib/server/performance.js';
let booted = false;
function boot(): void {
@@ -11,6 +13,7 @@ function boot(): void {
migrate();
interruptDeployments();
startWorker();
startPerformanceMonitor();
}
// SvelteKit calls handle() for every request; using the first request as the
@@ -18,5 +21,13 @@ function boot(): void {
// out-of-band init hook.
export const handle: Handle = async (input) => {
boot();
return authenticationHandle(input);
const started = performance.now();
const response = await authenticationHandle(input);
const elapsed = performance.now() - started;
response.headers.append('Server-Timing', `app;dur=${elapsed.toFixed(1)}`);
if (process.env.EC_PERF_LOG === 'true' && elapsed > 250 && !input.event.route.id?.startsWith('/api/agent/')) {
console.info('[request]', { route: input.event.route.id, method: input.event.request.method, status: response.status, elapsedMs: Math.round(elapsed) });
}
if (input.event.locals.user && !['GET','HEAD','OPTIONS'].includes(input.event.request.method) && response.status < 400) emit({ type: 'fleet-invalidated' });
return response;
};