UNPKG

trigger.dev

Version:

A Command-Line Interface for Trigger.dev projects

65 lines 2.47 kB
import { execOptionsForRuntime } from "@trigger.dev/core/v3/build"; import { join } from "node:path"; import { indexWorkerManifest } from "../indexing/indexWorkerManifest.js"; import { prettyError } from "../utilities/cliOutput.js"; import { writeJSONFile } from "../utilities/fileSystem.js"; import { logger } from "../utilities/logger.js"; export class BackgroundWorker { build; metafile; params; deprecated = false; manifest; serverWorker; constructor(build, metafile, params) { this.build = build; this.metafile = metafile; this.params = params; } deprecate() { this.deprecated = true; } get workerManifestPath() { return join(this.build.outputPath, "index.json"); } get buildManifestPath() { return join(this.build.outputPath, "build.json"); } stop() { logger.debug("[BackgroundWorker] Stopping worker", { version: this.serverWorker?.version, outputPath: this.build.outputPath, }); this.params.stop(); } async initialize() { if (this.manifest) { throw new Error("Worker already initialized"); } // Write the build manifest to this.build.outputPath/build.json await writeJSONFile(this.buildManifestPath, this.build, true); logger.debug("indexing worker manifest", { build: this.build, params: this.params }); this.manifest = await indexWorkerManifest({ runtime: this.build.runtime, indexWorkerPath: this.build.indexWorkerEntryPoint, buildManifestPath: this.buildManifestPath, nodeOptions: execOptionsForRuntime(this.build.runtime, this.build), env: this.params.env, cwd: this.params.cwd, otelHookInclude: this.build.otelImportHook?.include, otelHookExclude: this.build.otelImportHook?.exclude, handleStdout(data) { logger.debug(data); }, handleStderr(data) { if (!data.includes("Debugger attached")) { prettyError(data.toString()); } }, }); // Write the build manifest to this.build.outputPath/worker.json await writeJSONFile(this.workerManifestPath, this.manifest, true); logger.debug("worker manifest indexed", { path: this.build.outputPath }); } } //# sourceMappingURL=backgroundWorker.js.map