-
-
Notifications
You must be signed in to change notification settings - Fork 915
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
14
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
14 commits
Select commit
Hold shift + click to select a range
c7bfe5c
WIP
ericallam 38c4cd2
some fixes
ericallam 4654592
fair queue baby
ericallam 45c335f
wip of the streaming batch trigger stuff
ericallam 61d6431
new async iterable version of batch trigger
ericallam eef5061
pnpm lock changes
ericallam d7effbd
add new batch status to api schema
ericallam e558d1e
Handle large payloads and correct the trace ID propogation to child runs
ericallam e366c75
record when the batch processing is completed
ericallam dcb03ef
more batch processing work
ericallam 3ed008d
better dequeuing from fair queue
ericallam 342c9fc
fixed tests and removed the run number incrementor from the run engin…
ericallam ef76ff7
restructure the batch queue callbacks to prevent circular import
ericallam daa0b5b
handle batch failures more reliably
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
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.