triggerdotdev / trigger.dev

Trigger.dev is the open source background jobs platform.
https://trigger.dev/changelog
Apache License 2.0
8.21k stars 485 forks source link

feat: support async `io.runTask` error callback #909

Open minyoung opened 6 months ago

minyoung commented 6 months ago

Is your feature request related to a problem? Please describe.

When io.runTask runs, it has an onError callback option. This is great! But I have some async logic that I would like to run in this error callback. This is currently not supported since the error callback cannot return a promise.

Describe the solution you'd like to see

Update RunTaskErrorCallback type to allow returning a promise, and update io.runTask to await onError(error, task, this)

Describe alternate solutions

Do nothing and tell developers to try/catch inside the io.runTask (where it is async):

io.runTask(
  "name",
  async (task) => {
    try {
      // ...
    } catch (error) {
      await sendErrorNotification(payload)
    }
  },
)

Additional information

No response

pnoyens commented 3 months ago

Try wrapping your io.runTask inside this: https://trigger.dev/docs/sdk/io/try

The catchCallback that comes with this, supports async code :)