Skip to content

Commit

Permalink
fix: run metadata not working when using npx/pnpm dlx
Browse files Browse the repository at this point in the history
  • Loading branch information
ericallam committed Sep 30, 2024
1 parent 8e38db9 commit 4c1ee3d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-falcons-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/core": patch
---

fix: run metadata not working when using npx/pnpm dlx
14 changes: 12 additions & 2 deletions packages/core/src/v3/runMetadata/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { DeserializedJson } from "../../schemas/json.js";
import { apiClientManager } from "../apiClientManager-api.js";
import { taskContext } from "../task-context-api.js";
import { getGlobal, registerGlobal } from "../utils/globals.js";
import { ApiRequestOptions } from "../zodfetch.js";

const API_NAME = "run-metadata";

export class RunMetadataAPI {
private static _instance?: RunMetadataAPI;
private store: Record<string, DeserializedJson> | undefined;

private constructor() {}

Expand All @@ -17,8 +19,16 @@ export class RunMetadataAPI {
return this._instance;
}

get store(): Record<string, DeserializedJson> | undefined {
return getGlobal(API_NAME);
}

set store(value: Record<string, DeserializedJson> | undefined) {
registerGlobal(API_NAME, value, true);
}

public enterWithMetadata(metadata: Record<string, DeserializedJson>): void {
this.store = metadata;
registerGlobal(API_NAME, metadata);
}

public current(): Record<string, DeserializedJson> | undefined {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/v3/utils/globals.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DeserializedJson } from "../../schemas/json.js";
import { ApiClientConfiguration } from "../apiClientManager/types.js";
import { Clock } from "../clock/clock.js";
import type { RuntimeManager } from "../runtime/manager.js";
Expand Down Expand Up @@ -54,4 +55,5 @@ type TriggerDotDevGlobalAPI = {
["task-catalog"]?: TaskCatalog;
["task-context"]?: TaskContext;
["api-client"]?: ApiClientConfiguration;
["run-metadata"]?: Record<string, DeserializedJson>;
};
2 changes: 2 additions & 0 deletions references/v3-catalog/src/trigger/runMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const runMetadataTask = task({
export const runMetadataChildTask = task({
id: "run-metadata-child-task",
run: async (payload: any, { ctx }) => {
logger.info("metadata", { metadata: metadata.current() });

await metadata.set("child", "task");

logger.info("metadata", { metadata: metadata.current() });
Expand Down

0 comments on commit 4c1ee3d

Please sign in to comment.