fix: run metadata not working when using npx/pnpm dlx

This commit is contained in:
Eric Allam
2024-09-29 19:09:38 -07:00
parent 8e38db96a5
commit 4c1ee3d6ea
4 changed files with 21 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@trigger.dev/core": patch
---
fix: run metadata not working when using npx/pnpm dlx
+12 -2
View File
@@ -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() {}
@@ -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 {
+2
View File
@@ -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";
@@ -54,4 +55,5 @@ type TriggerDotDevGlobalAPI = {
["task-catalog"]?: TaskCatalog;
["task-context"]?: TaskContext;
["api-client"]?: ApiClientConfiguration;
["run-metadata"]?: Record<string, DeserializedJson>;
};
@@ -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() });