Skip to content

Instantly share code, notes, and snippets.

@minyoung
Created February 23, 2024 20:43
Show Gist options
  • Save minyoung/1f165cca2f680795f0dd490ac0bda454 to your computer and use it in GitHub Desktop.
Save minyoung/1f165cca2f680795f0dd490ac0bda454 to your computer and use it in GitHub Desktop.
@trigger.dev/sdk patch to support async `io.runTask` error callback
diff --git a/dist/index.d.mts b/dist/index.d.mts
index 94a9e104e39ab2b9a1d4fbe59a3723f58e1d02a6..e1b7e1125e45fd918490eafeb1ed2f1194488a7a 100644
--- a/dist/index.d.mts
+++ b/dist/index.d.mts
@@ -1898,12 +1898,13 @@ type JsonRecord<T> = {
[Property in keyof T]: Json;
};
type Json<T = any> = JsonPrimitive | JsonArray | JsonRecord<T>;
-type RunTaskErrorCallback = (error: unknown, task: IOTask, io: IO) => {
+type RunTaskErrorCallbackReturn = {
retryAt?: Date;
error?: Error;
jitter?: number;
skipRetrying?: boolean;
} | Error | undefined | void;
+type RunTaskErrorCallback = (error: unknown, task: IOTask, io: IO) => RunTaskErrorCallbackReturn | Promise<RunTaskErrorCallbackReturn>;
type IOStats = {
initialCachedTasks: number;
lazyLoadedCachedTasks: number;
diff --git a/dist/index.d.ts b/dist/index.d.ts
index 94a9e104e39ab2b9a1d4fbe59a3723f58e1d02a6..e1b7e1125e45fd918490eafeb1ed2f1194488a7a 100644
--- a/dist/index.d.ts
+++ b/dist/index.d.ts
@@ -1898,12 +1898,13 @@ type JsonRecord<T> = {
[Property in keyof T]: Json;
};
type Json<T = any> = JsonPrimitive | JsonArray | JsonRecord<T>;
-type RunTaskErrorCallback = (error: unknown, task: IOTask, io: IO) => {
+type RunTaskErrorCallbackReturn = {
retryAt?: Date;
error?: Error;
jitter?: number;
skipRetrying?: boolean;
} | Error | undefined | void;
+type RunTaskErrorCallback = (error: unknown, task: IOTask, io: IO) => RunTaskErrorCallbackReturn | Promise<RunTaskErrorCallbackReturn>;
type IOStats = {
initialCachedTasks: number;
lazyLoadedCachedTasks: number;
diff --git a/dist/index.js b/dist/index.js
index 6beea3b8e3fbcfaf9294e7e8b5cedcb582eb0ce4..762928a0838c6611edaa224fe8dca0241adb3ed1 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -1538,7 +1538,7 @@ var _IO = class _IO {
let skipRetrying = false;
if (onError) {
try {
- const onErrorResult = onError(error, task, this);
+ const onErrorResult = await onError(error, task, this);
if (onErrorResult) {
if (onErrorResult instanceof Error) {
error = onErrorResult;
diff --git a/dist/index.mjs b/dist/index.mjs
index 9945e6f4a376339a16a50f60a52800c25690a858..d3dbfb9a467db248b49845c20ec3cc27f138f4ae 100644
--- a/dist/index.mjs
+++ b/dist/index.mjs
@@ -1530,7 +1530,7 @@ var _IO = class _IO {
let skipRetrying = false;
if (onError) {
try {
- const onErrorResult = onError(error, task, this);
+ const onErrorResult = await onError(error, task, this);
if (onErrorResult) {
if (onErrorResult instanceof Error) {
error = onErrorResult;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment