From de2bab85dd8c1cc5a924377f96a646fc2b72c853 Mon Sep 17 00:00:00 2001 From: CahidArda Date: Tue, 9 Sep 2025 17:19:15 +0300 Subject: [PATCH] feat: add notBefore parameter to client.trigger --- src/client/index.test.ts | 4 ++-- src/client/index.ts | 1 + src/client/types.ts | 10 ++++++++++ src/workflow-requests.ts | 4 +++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/client/index.test.ts b/src/client/index.test.ts index 23bdaf6..650ae84 100644 --- a/src/client/index.test.ts +++ b/src/client/index.test.ts @@ -276,7 +276,7 @@ describe("workflow client", () => { workflowRunId: myWorkflowRunId2, retries: 15, retryDelay: "2000", - delay: 1, + notBefore: new Date("2100-01-01T00:00:00Z").getTime() / 1000, useFailureFunction: true, }, ]); @@ -326,7 +326,7 @@ describe("workflow client", () => { "upstash-workflow-init": "true", "upstash-workflow-runid": `wfr_${myWorkflowRunId2}`, "upstash-workflow-url": "https://requestcatcher.com/api", - "upstash-delay": "1s", + "upstash-not-before": "4102444800", "content-type": "application/json", "upstash-feature-set": "LazyFetch,InitialBody,WF_DetectTrigger", "upstash-telemetry-framework": "unknown", diff --git a/src/client/index.ts b/src/client/index.ts index 3957cd4..21e677d 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -266,6 +266,7 @@ export class Client { workflowContext: context, telemetry: { sdk: SDK_TELEMETRY }, delay: option.delay, + notBefore: option.notBefore, }; }); const result = await triggerFirstInvocation(invocations); diff --git a/src/client/types.ts b/src/client/types.ts index 1d54f73..37dc87c 100644 --- a/src/client/types.ts +++ b/src/client/types.ts @@ -403,6 +403,16 @@ export type TriggerOptions = { * Delay to apply before triggering the workflow. */ delay?: PublishRequest["delay"]; + /** + * Optionally set the absolute delay of this message. + * This will override the delay option. + * The message will not delivered until the specified time. + * + * Unix timestamp in seconds. + * + * @default undefined + */ + notBefore?: PublishRequest["notBefore"]; /** * Label to apply to the workflow run. * diff --git a/src/workflow-requests.ts b/src/workflow-requests.ts index 58ad129..e1fdbcb 100644 --- a/src/workflow-requests.ts +++ b/src/workflow-requests.ts @@ -33,6 +33,7 @@ type TriggerFirstInvocationParams = { debug?: WorkflowLogger; invokeCount?: number; delay?: PublishRequest["delay"]; + notBefore?: PublishRequest["notBefore"]; }; export const triggerFirstInvocation = async ( @@ -44,7 +45,7 @@ export const triggerFirstInvocation = async ( const workflowContextClient = firstInvocationParams[0].workflowContext.qstashClient; const invocationBatch = firstInvocationParams.map( - ({ workflowContext, useJSONContent, telemetry, invokeCount, delay }) => { + ({ workflowContext, useJSONContent, telemetry, invokeCount, delay, notBefore }) => { const { headers } = getHeaders({ initHeaderValue: "true", workflowConfig: { @@ -93,6 +94,7 @@ export const triggerFirstInvocation = async ( body, url: workflowContext.url, delay: delay, + notBefore: notBefore, } as PublishBatchRequest; } );