perf: optimize dashboard loading and builds

This commit is contained in:
Thomas Camlong committed 2026-08-02 15:58:16 +02:00
1 parent d90e762e4b
commit de801f3f00
135 files changed
+8521 -1718

No files matched your search

+29 -11
View File
@@ -4,17 +4,35 @@ export async function register() {
const { createLogger } = await import("@homarr/core/infrastructure/logs");
const logger = createLogger({ module: "instrumentation" });
const services = [
{ name: "tasks", start: () => import("@homarr/tasks") },
{ name: "websocket", start: () => import("@homarr/websocket") },
];
const results = await Promise.allSettled(services.map(({ start }) => start()));
for (const [index, result] of results.entries()) {
if (result.status === "rejected") {
logger.error(
new Error(`Failed to start embedded ${services[index]?.name ?? "unknown"} service`, { cause: result.reason }),
);
const startTasksAsync = async () => {
try {
const tasks = await import("@homarr/tasks");
// Cron run-on-start hooks can perform slow external work. Keep dashboard
// readiness independent, but never leave the process permanently degraded.
void tasks.startupPromise.catch((cause: unknown) => {
logger.error(new Error("Failed to start embedded tasks service", { cause }));
process.exit(1);
});
} catch (cause) {
const error = new Error("Failed to load embedded tasks service", { cause });
logger.error(error);
throw error;
}
}
};
const startWebsocketAsync = async () => {
try {
const websocket = await import("@homarr/websocket");
// Listening is a bounded local readiness condition and prevents Next from
// becoming healthy with subscriptions unavailable.
await websocket.startupPromise;
} catch (cause) {
const error = new Error("Failed to start embedded websocket service", { cause });
logger.error(error);
throw error;
}
};
await Promise.all([startTasksAsync(), startWebsocketAsync()]);
}