Skip to content

Commit

Permalink
feat: support async io.runTask error callback
Browse files Browse the repository at this point in the history
  • Loading branch information
minyoung committed Feb 23, 2024
1 parent 07efef4 commit b038719
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-trainers-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/sdk": patch
---

support async `io.runTask` error callback
14 changes: 8 additions & 6 deletions packages/trigger-sdk/src/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,18 @@ type JsonArray = Json[];
type JsonRecord<T> = { [Property in keyof T]: Json };
export type Json<T = any> = JsonPrimitive | JsonArray | JsonRecord<T>;

export type RunTaskErrorCallback = (
error: unknown,
task: IOTask,
io: IO
) =>
type RunTaskErrorCallbackReturn =
| { retryAt?: Date; error?: Error; jitter?: number; skipRetrying?: boolean }
| Error
| undefined
| void;

export type RunTaskErrorCallback = (
error: unknown,
task: IOTask,
io: IO
) => RunTaskErrorCallbackReturn | Promise<RunTaskErrorCallbackReturn>;

export type IOStats = {
initialCachedTasks: number;
lazyLoadedCachedTasks: number;
Expand Down Expand Up @@ -1300,7 +1302,7 @@ export class IO {

if (onError) {
try {
const onErrorResult = onError(error, task, this);
const onErrorResult = await onError(error, task, this);

if (onErrorResult) {
if (onErrorResult instanceof Error) {
Expand Down

0 comments on commit b038719

Please sign in to comment.