Skip to content

Commit cb6e260

Browse files
committed
Add optional skipRetrying on runTask errors
1 parent 34c7baa commit cb6e260

File tree

1 file changed

+18
-8
lines changed
  • packages/trigger-sdk/src

1 file changed

+18
-8
lines changed

packages/trigger-sdk/src/io.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ export type RunTaskErrorCallback = (
5656
error: unknown,
5757
task: IOTask,
5858
io: IO
59-
) => { retryAt: Date; error?: Error; jitter?: number } | Error | undefined | void;
59+
) =>
60+
| { retryAt?: Date; error?: Error; jitter?: number; skipRetrying?: boolean }
61+
| Error
62+
| undefined
63+
| void;
6064

6165
export class IO {
6266
private _id: string;
@@ -574,6 +578,8 @@ export class IO {
574578
throw error;
575579
}
576580

581+
let skipRetrying = false;
582+
577583
if (onError) {
578584
try {
579585
const onErrorResult = onError(error, task, this);
@@ -582,13 +588,17 @@ export class IO {
582588
if (onErrorResult instanceof Error) {
583589
error = onErrorResult;
584590
} else {
585-
const parsedError = ErrorWithStackSchema.safeParse(onErrorResult.error);
591+
skipRetrying = !!onErrorResult.skipRetrying;
592+
593+
if (onErrorResult.retryAt && !skipRetrying) {
594+
const parsedError = ErrorWithStackSchema.safeParse(onErrorResult.error);
586595

587-
throw new RetryWithTaskError(
588-
parsedError.success ? parsedError.data : { message: "Unknown error" },
589-
task,
590-
onErrorResult.retryAt
591-
);
596+
throw new RetryWithTaskError(
597+
parsedError.success ? parsedError.data : { message: "Unknown error" },
598+
task,
599+
onErrorResult.retryAt
600+
);
601+
}
592602
}
593603
}
594604
} catch (innerError) {
@@ -602,7 +612,7 @@ export class IO {
602612

603613
const parsedError = ErrorWithStackSchema.safeParse(error);
604614

605-
if (options?.retry) {
615+
if (options?.retry && !skipRetrying) {
606616
const retryAt = calculateRetryAt(options.retry, task.attempts - 1);
607617

608618
if (retryAt) {

0 commit comments

Comments
 (0)