Skip to content

Commit dd4515a

Browse files
authored
Merge pull request #2379 from triggerdotdev/remove-trigger-and-poll
Remove triggerAndPoll()
2 parents 21c2c13 + 97e5c22 commit dd4515a

File tree

6 files changed

+10
-94
lines changed

6 files changed

+10
-94
lines changed

.changeset/slow-games-drum.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/sdk": patch
3+
---
4+
5+
Removed triggerAndPoll. It was never recommended so it's been removed.

.cursor/rules/writing-tasks.mdc

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -431,28 +431,6 @@ export async function POST(request: Request) {
431431
}
432432
```
433433

434-
### tasks.triggerAndPoll()
435-
436-
Triggers a task and polls until completion. Not recommended for web requests as it blocks until the run completes. Consider using Realtime docs for better alternatives.
437-
438-
```ts
439-
import { tasks } from "@trigger.dev/sdk/v3";
440-
import type { emailSequence } from "~/trigger/emails";
441-
442-
export async function POST(request: Request) {
443-
const data = await request.json();
444-
const result = await tasks.triggerAndPoll<typeof emailSequence>(
445-
"email-sequence",
446-
{
447-
to: data.email,
448-
name: data.name,
449-
},
450-
{ pollIntervalMs: 5000 }
451-
);
452-
return Response.json(result);
453-
}
454-
```
455-
456434
### batch.trigger()
457435

458436
Triggers multiple runs of different tasks at once, useful when you need to execute multiple tasks simultaneously.

docs/triggering.mdx

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ description: "Tasks need to be triggered in order to run."
77

88
Trigger tasks **from your backend**:
99

10-
| Function | What it does | |
11-
| :----------------------- | :----------------------------------------------------------------------------------------------- | ----------------------------- |
12-
| `tasks.trigger()` | Triggers a task and returns a handle you can use to fetch and manage the run. | [Docs](#tasks-trigger) |
13-
| `tasks.batchTrigger()` | Triggers a single task in a batch and returns a handle you can use to fetch and manage the runs. | [Docs](#tasks-batchtrigger) |
14-
| `tasks.triggerAndPoll()` | Triggers a task and then polls the run until it’s complete. | [Docs](#tasks-triggerandpoll) |
15-
| `batch.trigger()` | Similar to `tasks.batchTrigger` but allows running multiple different tasks | [Docs](#batch-trigger) |
10+
| Function | What it does | |
11+
| :--------------------- | :----------------------------------------------------------------------------------------------- | --------------------------- |
12+
| `tasks.trigger()` | Triggers a task and returns a handle you can use to fetch and manage the run. | [Docs](#tasks-trigger) |
13+
| `tasks.batchTrigger()` | Triggers a single task in a batch and returns a handle you can use to fetch and manage the runs. | [Docs](#tasks-batchtrigger) |
14+
| `batch.trigger()` | Similar to `tasks.batchTrigger` but allows running multiple different tasks | [Docs](#batch-trigger) |
1615

1716
Trigger tasks **from inside a another task**:
1817

@@ -162,40 +161,6 @@ export async function POST(request: Request) {
162161
}
163162
```
164163

165-
### tasks.triggerAndPoll()
166-
167-
Triggers a single run of a task with the payload you pass in, and any options you specify, and then polls the run until it's complete.
168-
169-
<Warning>
170-
We don't recommend using `triggerAndPoll()`, especially inside a web request, as it will block the
171-
request until the run is complete. Please see our [Realtime docs](/realtime) for a better way to
172-
handle this.
173-
</Warning>
174-
175-
```ts Your backend
176-
import { tasks } from "@trigger.dev/sdk/v3";
177-
import type { emailSequence } from "~/trigger/emails";
178-
179-
//app/email/route.ts
180-
export async function POST(request: Request) {
181-
//get the JSON from the request
182-
const data = await request.json();
183-
184-
// Pass the task type to `triggerAndPoll()` as a generic argument, giving you full type checking
185-
const result = await tasks.triggerAndPoll<typeof emailSequence>(
186-
"email-sequence",
187-
{
188-
to: data.email,
189-
name: data.name,
190-
},
191-
{ pollIntervalMs: 5000 }
192-
);
193-
194-
//return a success response with the result
195-
return Response.json(result);
196-
}
197-
```
198-
199164
### batch.trigger()
200165

201166
Triggers multiple runs of different tasks with the payloads you pass in, and any options you specify. This is useful when you need to trigger multiple tasks at once.

packages/trigger-sdk/src/v3/shared.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -490,32 +490,6 @@ export async function batchTriggerAndWait<TTask extends AnyTask>(
490490
>("tasks.batchTriggerAndWait()", id, items, undefined, options, requestOptions);
491491
}
492492

493-
/**
494-
* Trigger a task by its identifier with the given payload and poll until the run is completed.
495-
*
496-
* @example
497-
*
498-
* ```ts
499-
* import { tasks, runs } from "@trigger.dev/sdk/v3";
500-
* import type { myTask } from "./myTasks"; // Import just the type of the task
501-
*
502-
* const run = await tasks.triggerAndPoll<typeof myTask>("my-task", { foo: "bar" }); // The id and payload are fully typesafe
503-
* console.log(run.output) // The output is also fully typed
504-
* ```
505-
*
506-
* @returns {Run} The completed run, either successful or failed.
507-
*/
508-
export async function triggerAndPoll<TTask extends AnyTask>(
509-
id: TaskIdentifier<TTask>,
510-
payload: TaskPayload<TTask>,
511-
options?: TriggerOptions & PollOptions,
512-
requestOptions?: TriggerApiRequestOptions
513-
): Promise<RetrieveRunResult<TTask>> {
514-
const handle = await trigger(id, payload, options, requestOptions);
515-
516-
return runs.poll(handle, options, requestOptions);
517-
}
518-
519493
export async function batchTrigger<TTask extends AnyTask>(
520494
id: TaskIdentifier<TTask>,
521495
items: Array<BatchItem<TaskPayload<TTask>>>,

packages/trigger-sdk/src/v3/tasks.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
createToolTask,
1919
SubtaskUnwrapError,
2020
trigger,
21-
triggerAndPoll,
2221
triggerAndWait,
2322
} from "./shared.js";
2423

@@ -86,7 +85,6 @@ export const toolTask = createToolTask;
8685

8786
export const tasks = {
8887
trigger,
89-
triggerAndPoll,
9088
batchTrigger,
9189
triggerAndWait,
9290
batchTriggerAndWait,

references/v3-catalog/src/trigger/sdkUsage.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ export const sdkUsage = task({
1414
run: $firstRun,
1515
});
1616

17-
await tasks.triggerAndPoll<typeof sdkChild>("sdk-child", {
18-
handle,
19-
});
20-
2117
const replayedRun = await runs.replay($firstRun.id);
2218

2319
await runs.cancel(replayedRun.id);

0 commit comments

Comments
 (0)