Skip to content

Commit d68057a

Browse files
authored
feat: add notBefore parameter to client.trigger (#129)
1 parent cd98f7d commit d68057a

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

src/client/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ describe("workflow client", () => {
276276
workflowRunId: myWorkflowRunId2,
277277
retries: 15,
278278
retryDelay: "2000",
279-
delay: 1,
279+
notBefore: new Date("2100-01-01T00:00:00Z").getTime() / 1000,
280280
useFailureFunction: true,
281281
},
282282
]);
@@ -326,7 +326,7 @@ describe("workflow client", () => {
326326
"upstash-workflow-init": "true",
327327
"upstash-workflow-runid": `wfr_${myWorkflowRunId2}`,
328328
"upstash-workflow-url": "https://requestcatcher.com/api",
329-
"upstash-delay": "1s",
329+
"upstash-not-before": "4102444800",
330330
"content-type": "application/json",
331331
"upstash-feature-set": "LazyFetch,InitialBody,WF_DetectTrigger",
332332
"upstash-telemetry-framework": "unknown",

src/client/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ export class Client {
266266
workflowContext: context,
267267
telemetry: { sdk: SDK_TELEMETRY },
268268
delay: option.delay,
269+
notBefore: option.notBefore,
269270
};
270271
});
271272
const result = await triggerFirstInvocation(invocations);

src/client/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,16 @@ export type TriggerOptions = {
403403
* Delay to apply before triggering the workflow.
404404
*/
405405
delay?: PublishRequest["delay"];
406+
/**
407+
* Optionally set the absolute delay of this message.
408+
* This will override the delay option.
409+
* The message will not delivered until the specified time.
410+
*
411+
* Unix timestamp in seconds.
412+
*
413+
* @default undefined
414+
*/
415+
notBefore?: PublishRequest["notBefore"];
406416
/**
407417
* Label to apply to the workflow run.
408418
*

src/workflow-requests.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type TriggerFirstInvocationParams<TInitialPayload> = {
3333
debug?: WorkflowLogger;
3434
invokeCount?: number;
3535
delay?: PublishRequest["delay"];
36+
notBefore?: PublishRequest["notBefore"];
3637
};
3738

3839
export const triggerFirstInvocation = async <TInitialPayload>(
@@ -44,7 +45,7 @@ export const triggerFirstInvocation = async <TInitialPayload>(
4445
const workflowContextClient = firstInvocationParams[0].workflowContext.qstashClient;
4546

4647
const invocationBatch = firstInvocationParams.map(
47-
({ workflowContext, useJSONContent, telemetry, invokeCount, delay }) => {
48+
({ workflowContext, useJSONContent, telemetry, invokeCount, delay, notBefore }) => {
4849
const { headers } = getHeaders({
4950
initHeaderValue: "true",
5051
workflowConfig: {
@@ -93,6 +94,7 @@ export const triggerFirstInvocation = async <TInitialPayload>(
9394
body,
9495
url: workflowContext.url,
9596
delay: delay,
97+
notBefore: notBefore,
9698
} as PublishBatchRequest;
9799
}
98100
);

0 commit comments

Comments
 (0)