UNPKG

@mastra/core

Version:
70 lines (67 loc) 1.78 kB
'use strict'; // src/worker/worker.ts var MastraWorker = class { mastra; deps; /** Called by Mastra during registration to provide the instance reference. */ __registerMastra(mastra) { this.mastra = mastra; } /** Initialize with infrastructure deps. Called before start(). */ async init(deps) { this.deps = deps; if (!this.mastra && deps.mastra) { this.mastra = deps.mastra; } } }; // src/worker/transport/pull-transport.ts var TOPIC_WORKFLOWS = "workflows"; var PullTransport = class { #pubsub; #group; #topic; #logger; #callbacks = []; constructor({ pubsub, group, topic, logger }) { this.#pubsub = pubsub; this.#group = group; this.#topic = topic ?? TOPIC_WORKFLOWS; this.#logger = logger; } async start(router) { if (this.#callbacks.length > 0) { this.#logger?.debug("[PullTransport] start() called while already subscribed; ignoring duplicate call"); return; } const cb = (event, ack, nack) => { router.route(event, ack, nack).catch((err) => { try { if (typeof nack === "function") { void nack(); } } finally { this.#logger?.error("[PullTransport] router.route rejected", { err }); } }); }; await this.#pubsub.subscribe(this.#topic, cb, { group: this.#group }); this.#callbacks.push({ topic: this.#topic, cb }); } async stop() { for (const { topic, cb } of this.#callbacks) { await this.#pubsub.unsubscribe(topic, cb); } this.#callbacks = []; await this.#pubsub.flush(); } }; exports.MastraWorker = MastraWorker; exports.PullTransport = PullTransport; //# sourceMappingURL=chunk-CWKMGK5K.cjs.map //# sourceMappingURL=chunk-CWKMGK5K.cjs.map