refactor(bootstrap): extract bootstrap-application into orchestrator + modules

Splits the 391-line bootstrapApplication god function into a thin
orchestrator plus 7 focused modules under src/main/bootstrap/:
prepare-logger, prepare-database, prepare-services (service graph +
ipc wiring), wire-api-server (14-callback dictionary), recover-
scheduled-posts, run-startup-health-checks, recover-interrupted-tasks
(crash notification + clean-shutdown task resumption). Original
startup order, before-quit cleanup, and error handling are preserved;
the entry file drops to 153 lines.
This commit is contained in:
ZacharyZhang-NY committed 2026-04-16 23:34:13 -04:00
1 parent dd007760b8
commit a2a90f00e6
8 files changed
+487 -308

No files matched your search

@@ -0,0 +1,28 @@
import type { AppDatabase } from "../database";
import type { createConnectorHealthService } from "../connector-health-service";
interface Logger {
info: (...args: unknown[]) => void;
warn: (...args: unknown[]) => void;
}
type ConnectorHealthService = ReturnType<typeof createConnectorHealthService>;
export async function runStartupHealthChecks(
db: AppDatabase,
connectorHealth: ConnectorHealthService | null | undefined,
logger: Logger,
): Promise<void> {
if (!connectorHealth) return;
const connectors = db.listSnapshot().connectors;
const results = await Promise.allSettled(
connectors.map((connector) => connectorHealth.checkConnector(connector.id)),
);
for (let i = 0; i < results.length; i++) {
const result = results[i]!;
if (result.status === "rejected") {
logger.warn(`[bootstrap] Connector health check failed for ${connectors[i]?.id}: ${result.reason instanceof Error ? result.reason.message : String(result.reason)}`);
}
}
logger.info(`[bootstrap] Connector health checks completed (${results.filter((r) => r.status === "fulfilled").length}/${connectors.length} succeeded)`);
}