-
-
Notifications
You must be signed in to change notification settings - Fork 918
feat(engine): Batch trigger reloaded #2779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ericallam
wants to merge
32
commits into
main
Choose a base branch
from
feat/batch-trigger-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
0550658
WIP
ericallam 7b5056b
some fixes
ericallam ceddba0
fair queue baby
ericallam c1743bb
wip of the streaming batch trigger stuff
ericallam 8a9532d
new async iterable version of batch trigger
ericallam fdbed14
pnpm lock changes
ericallam 98a5709
add new batch status to api schema
ericallam f066ae5
Handle large payloads and correct the trace ID propogation to child runs
ericallam 8552b3d
record when the batch processing is completed
ericallam d72068c
more batch processing work
ericallam d55dbb4
better dequeuing from fair queue
ericallam 08eb6dd
fixed tests and removed the run number incrementor from the run engin…
ericallam 7c85267
restructure the batch queue callbacks to prevent circular import
ericallam f3354b1
handle batch failures more reliably
ericallam 00d5428
Better handling of batches when sealed = false
ericallam 4d76367
improve completion tracker callback calling and cleanup
ericallam 6c6de84
Add unique index to batch task run errors on the index field and more…
ericallam d69cfa5
batch task run seal update is atomic
ericallam 5b8ec88
better ndjson parsing with bounded memory usage
ericallam 5211ba6
release concurrency slot when moving to the DLQ
ericallam f592aac
Fix fair queue heartbeat
ericallam 1610766
fixed batch payload handling
ericallam da247bf
capture and pass the planType through to triggering
ericallam b77c910
should preserve runFriendlyId across retries when RunDuplicateIdempot…
ericallam 02eec34
better handling streaming ndjson retries
ericallam 8f1619b
Better batch friendly ID parsing errors
ericallam 82da484
only parse payloads when they are application/json
ericallam 7e073b4
fix batch queue redis config
ericallam a5791a0
cancel read stream before releasing lock
ericallam 628a7d2
Add changeset
ericallam fce7874
Fix stream batch items test
ericallam e78b619
all tests should use root vitest
ericallam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| --- | ||
| "@trigger.dev/sdk": patch | ||
| --- | ||
|
|
||
| feat: Support for new batch trigger system |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,122 @@ | ||
| import { type BatchTaskRunStatus } from "@trigger.dev/database"; | ||
| import { displayableEnvironment } from "~/models/runtimeEnvironment.server"; | ||
| import { engine } from "~/v3/runEngine.server"; | ||
| import { BasePresenter } from "./basePresenter.server"; | ||
|
|
||
| type BatchPresenterOptions = { | ||
| environmentId: string; | ||
| batchId: string; | ||
| userId?: string; | ||
| }; | ||
|
|
||
| export type BatchPresenterData = Awaited<ReturnType<BatchPresenter["call"]>>; | ||
|
|
||
| export class BatchPresenter extends BasePresenter { | ||
| public async call({ environmentId, batchId, userId }: BatchPresenterOptions) { | ||
| const batch = await this._replica.batchTaskRun.findFirst({ | ||
| select: { | ||
| id: true, | ||
| friendlyId: true, | ||
| status: true, | ||
| runCount: true, | ||
| batchVersion: true, | ||
| createdAt: true, | ||
| updatedAt: true, | ||
| completedAt: true, | ||
| processingStartedAt: true, | ||
| processingCompletedAt: true, | ||
| successfulRunCount: true, | ||
| failedRunCount: true, | ||
| idempotencyKey: true, | ||
| runtimeEnvironment: { | ||
| select: { | ||
| id: true, | ||
| type: true, | ||
| slug: true, | ||
| orgMember: { | ||
| select: { | ||
| user: { | ||
| select: { | ||
| id: true, | ||
| name: true, | ||
| displayName: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| errors: { | ||
| select: { | ||
| id: true, | ||
| index: true, | ||
| taskIdentifier: true, | ||
| error: true, | ||
| errorCode: true, | ||
| createdAt: true, | ||
| }, | ||
| orderBy: { | ||
| index: "asc", | ||
| }, | ||
| }, | ||
| }, | ||
| where: { | ||
| runtimeEnvironmentId: environmentId, | ||
| friendlyId: batchId, | ||
| }, | ||
| }); | ||
|
|
||
| if (!batch) { | ||
| throw new Error("Batch not found"); | ||
| } | ||
|
|
||
| const hasFinished = batch.status !== "PENDING" && batch.status !== "PROCESSING"; | ||
| const isV2 = batch.batchVersion === "runengine:v2"; | ||
|
|
||
| // For v2 batches in PROCESSING state, get live progress from Redis | ||
| // This provides real-time updates without waiting for the batch to complete | ||
| let liveSuccessCount = batch.successfulRunCount ?? 0; | ||
| let liveFailureCount = batch.failedRunCount ?? 0; | ||
|
|
||
| if (isV2 && batch.status === "PROCESSING") { | ||
| const liveProgress = await engine.getBatchQueueProgress(batch.id); | ||
| if (liveProgress) { | ||
| liveSuccessCount = liveProgress.successCount; | ||
| liveFailureCount = liveProgress.failureCount; | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| id: batch.id, | ||
| friendlyId: batch.friendlyId, | ||
| status: batch.status as BatchTaskRunStatus, | ||
| runCount: batch.runCount, | ||
| batchVersion: batch.batchVersion, | ||
| isV2, | ||
| createdAt: batch.createdAt.toISOString(), | ||
| updatedAt: batch.updatedAt.toISOString(), | ||
| completedAt: batch.completedAt?.toISOString(), | ||
| processingStartedAt: batch.processingStartedAt?.toISOString(), | ||
| processingCompletedAt: batch.processingCompletedAt?.toISOString(), | ||
| finishedAt: batch.completedAt | ||
| ? batch.completedAt.toISOString() | ||
| : hasFinished | ||
| ? batch.updatedAt.toISOString() | ||
| : undefined, | ||
| hasFinished, | ||
| successfulRunCount: liveSuccessCount, | ||
| failedRunCount: liveFailureCount, | ||
| idempotencyKey: batch.idempotencyKey, | ||
| environment: displayableEnvironment(batch.runtimeEnvironment, userId), | ||
| errors: batch.errors.map((error) => ({ | ||
| id: error.id, | ||
| index: error.index, | ||
| taskIdentifier: error.taskIdentifier, | ||
| error: error.error, | ||
| errorCode: error.errorCode, | ||
| createdAt: error.createdAt.toISOString(), | ||
| })), | ||
| }; | ||
| } | ||
| } | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.