-
-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates the
trigger
, batchTrigger
and their *AndWait
variants t…
…o use the first parameter for the payload/items, and the second parameter for options (#1045) Also always returns a `TaskRunResult` object from `triggerAndWait` instead of rethrowing subtask errors in the parent
- Loading branch information
Showing
18 changed files
with
373 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
"@trigger.dev/sdk": patch | ||
"@trigger.dev/core": patch | ||
--- | ||
|
||
Updates the `trigger`, `batchTrigger` and their `*AndWait` variants to use the first parameter for the payload/items, and the second parameter for options. | ||
|
||
Before: | ||
|
||
```ts | ||
await yourTask.trigger({ payload: { foo: "bar" }, options: { idempotencyKey: "key_1234" } }); | ||
await yourTask.triggerAndWait({ payload: { foo: "bar" }, options: { idempotencyKey: "key_1234" } }); | ||
|
||
await yourTask.batchTrigger({ items: [{ payload: { foo: "bar" } }, { payload: { foo: "baz" } }] }); | ||
await yourTask.batchTriggerAndWait({ items: [{ payload: { foo: "bar" } }, { payload: { foo: "baz" } }] }); | ||
``` | ||
|
||
After: | ||
|
||
```ts | ||
await yourTask.trigger({ foo: "bar" }, { idempotencyKey: "key_1234" }); | ||
await yourTask.triggerAndWait({ foo: "bar" }, { idempotencyKey: "key_1234" }); | ||
|
||
await yourTask.batchTrigger([{ payload: { foo: "bar" } }, { payload: { foo: "baz" } }]); | ||
await yourTask.batchTriggerAndWait([{ payload: { foo: "bar" } }, { payload: { foo: "baz" } }]); | ||
``` | ||
|
||
We've also changed the API of the `triggerAndWait` result. Before, if the subtask that was triggered finished with an error, we would automatically "rethrow" the error in the parent task. | ||
|
||
Now instead we're returning a `TaskRunResult` object that allows you to discriminate between successful and failed runs in the subtask: | ||
|
||
Before: | ||
|
||
```ts | ||
try { | ||
const result = await yourTask.triggerAndWait({ foo: "bar" }); | ||
|
||
// result is the output of your task | ||
console.log("result", result); | ||
|
||
} catch (error) { | ||
// handle subtask errors here | ||
} | ||
``` | ||
|
||
After: | ||
|
||
```ts | ||
const result = await yourTask.triggerAndWait({ foo: "bar" }); | ||
|
||
if (result.ok) { | ||
console.log(`Run ${result.id} succeeded with output`, result.output); | ||
} else { | ||
console.log(`Run ${result.id} failed with error`, result.error); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.