An open-source, self-hosted system for apps built with web technologies.
Order Process creation before run startup
zohayrslileh7dafb1027f97
diff --git a/scripts/contracts/process-lifecycle.ts b/scripts/contracts/process-lifecycle.tsindex 8a22c6c..fb67c35 100644--- a/scripts/contracts/process-lifecycle.ts+++ b/scripts/contracts/process-lifecycle.ts@@ -68,7 +68,7 @@ async function register(manager: ProcessManager, identity: string) {false,null,null,- () => { throw new Error("configuration failed") }+ { prepare() { throw new Error("configuration failed") } }), /configuration failed/)assert.equal(manager.processes.has("failed-registration"), false)@@ -101,6 +101,30 @@ async function register(manager: ProcessManager, identity: string) {assert.equal(manager.processes.has("partial-registration"), false)}+// A launcher can only receive a started Process after the authoritative+// representation has received that Process's creation snapshot.+{+ const manager = processManager()+ const order: string[] = []++ manager.$outbound.subscribe("/created", () => { order.push("published") })++ await manager.register(+ "ordered-registration",+ null,+ program("ordered-registration"),+ {},+ launch,+ null,+ false,+ null,+ null,+ { created() { order.push("reported") } }+ )++ assert.deepEqual(order, ["published", "reported"])+}+// A failing observer is not allowed to stop the authoritative teardown or// prevent later terminal publications from running.{diff --git a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts b/source/server/core/link-manager/auth-manager/process-manager/process-manager.tsindex d29b1dc..d3fba98 100644--- a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts+++ b/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts@@ -907,7 +907,7 @@ export default class ProcessManager extends TheLink {return new Window(shown, shape.position, shape.size, ++this.highest, shape.minimize)}- public async register(identity: string, name: string | null, program: Program, options: Options, launch: ProcessLaunch, runtime: ServerRuntime | null, client: boolean, shape: Shape | null, parent: Process | null, configure?: (process: Process) => void) {+ public async register(identity: string, name: string | null, program: Program, options: Options, launch: ProcessLaunch, runtime: ServerRuntime | null, client: boolean, shape: Shape | null, parent: Process | null, registration?: ProcessRegistration) {if (this.processes.has(identity)) {@@ -965,7 +965,7 @@ export default class ProcessManager extends TheLink {try {- configure?.(process)+ registration?.prepare?.(process)// Initial activation is one endpoint transition too. A server that// exits immediately is queued behind it, preserving the only coherent@@ -988,6 +988,8 @@ export default class ProcessManager extends TheLink {await this.$outbound.publish("/created", process.hosted())+ registration?.created?.(process)+if (window) this.settleFront(window.layer, front)if (process.server) await this.serverStarted(process)@@ -2792,6 +2794,15 @@ export default class ProcessManager extends TheLink {}}+interface ProcessRegistration {++ /** Attach observers before either Endpoint can emit output or exit. */+ prepare?: (process: Process) => void++ /** Report creation only after the authoritative Process snapshot is published. */+ created?: (process: Process) => void+}+function permissionChange<Name extends PermissionName>(permission: Permission<Name>, needReload: boolean): PermissionChange<Name> {return Object.freeze({diff --git a/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts b/source/server/core/link-manager/auth-manager/program-manager/program-manager.tsindex 2c08a97..71da633 100644--- a/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts+++ b/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts@@ -1288,22 +1288,18 @@ export default class ProgramManager extends TheLink {// Lifecycle consumers are attached before either initial endpoint is// activated, so even a server command that exits immediately has a// complete output and exit record.- await this.authManager.processManager.register(identity, launch.name ?? null, program, options, resolved.intent, runtime, client !== null, shape, parent, record => {-- record.onServerStart(server => server.onOutput((stream, text) => logs.printed(identity, stream === "err" ? "stderr" : "stdout", text)))-- record.onServerStop((code, signal) => logs.endpointExited(identity, "server", code, signal))-- record.onClientStop(() => logs.endpointExited(identity, "client", null, null))-- if (watching) {-- watching.started?.(record)-- record.onServerStart(server => server.onOutput(watching.output))-- record.onExit(watching.exited)- }+ await this.authManager.processManager.register(identity, launch.name ?? null, program, options, resolved.intent, runtime, client !== null, shape, parent, {+ prepare: record => {+ record.onServerStart(server => server.onOutput((stream, text) => logs.printed(identity, stream === "err" ? "stderr" : "stdout", text)))+ record.onServerStop((code, signal) => logs.endpointExited(identity, "server", code, signal))+ record.onClientStop(() => logs.endpointExited(identity, "client", null, null))++ if (watching) {+ record.onServerStart(server => server.onOutput(watching.output))+ record.onExit(watching.exited)+ }+ },+ created: record => watching?.started?.(record)})return identity