The node's runtime is its modules' bus: it binds each module's consumer and hands its events to the bundle (hq ADR 0198)
A launched bundle's mesh/subscribe binds the module's own durable consumer — EVENTS, <node>_<module>, by name as the module's own runtime bound it, so nothing is lost or replayed in the move — and every event goes to each child of the module that subscribed as mesh/event, acknowledged only when all answered, negatively acknowledged after a short delay when one failed or died, terminated when it is not an event. mesh/ask calls a tool as the module. Every launched bundle is started again when it exits, with backoff, since long-running code waits for no call. Requires SDK 0.1.6.
This commit is contained in:
+7
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
// A long-running bundle that keeps exiting (novox/hq ADR 0198): the runtime starts it again each time.
|
||||
import { appendFileSync } from "node:fs";
|
||||
import { serveStdio } from "@novox/mesh-sdk/stdio";
|
||||
appendFileSync(process.env.FLAKY_LOG, "started\n");
|
||||
setTimeout(() => process.exit(3), 300);
|
||||
await serveStdio("flaky", []);
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
// A module whose code runs long (novox/hq ADR 0198): it subscribes as it is imported, handles each
|
||||
// event once it can, fails the first time it is asked to, dies the first time it is told to, and one
|
||||
// tool asks another module's tool through the runtime. What it did is written to WATCH_LOG.
|
||||
import { appendFileSync, existsSync, writeFileSync } from "node:fs";
|
||||
import { on } from "@novox/mesh-sdk/events";
|
||||
import { broker } from "@novox/mesh-sdk/messaging";
|
||||
import { registerModuleTools } from "@novox/mesh-sdk/tools";
|
||||
|
||||
const log = process.env.WATCH_LOG;
|
||||
const once = (mark) => {
|
||||
const file = `${log}.${mark}`;
|
||||
if (existsSync(file)) return false;
|
||||
writeFileSync(file, "1");
|
||||
return true;
|
||||
};
|
||||
appendFileSync(log, "started\n");
|
||||
await on("alpha.happened", async (e) => {
|
||||
if (e.body.fail && once(`fail-${e.body.n}`)) throw new Error(`not yet ${e.body.n}`);
|
||||
if (e.body.die && once(`die-${e.body.n}`)) process.exit(7);
|
||||
appendFileSync(log, `handled ${e.body.n}\n`);
|
||||
});
|
||||
registerModuleTools("watcher", () => [
|
||||
{ name: "relay", description: "asks beta", input: {}, run: async () => broker().request("beta.three", {}) },
|
||||
]);
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
// The launcher the builder writes beside an entrypoint (novox/hq ADR 0193), for watcher.mjs.
|
||||
import { serveRegisteredOverStdio } from "@novox/mesh-sdk/stdio";
|
||||
await import("./watcher.mjs");
|
||||
await serveRegisteredOverStdio();
|
||||
Reference in New Issue
Block a user