File tree Expand file tree Collapse file tree 9 files changed +56
-27
lines changed
_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.batches.$batchParam
internal-packages/database/prisma
migrations/20251209155209_add_processing_completed_at_to_batch_task_run
references/hello-world/src/trigger Expand file tree Collapse file tree 9 files changed +56
-27
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ export class BatchPresenter extends BasePresenter {
2424 updatedAt : true ,
2525 completedAt : true ,
2626 processingStartedAt : true ,
27+ processingCompletedAt : true ,
2728 successfulRunCount : true ,
2829 failedRunCount : true ,
2930 idempotencyKey : true ,
@@ -96,6 +97,7 @@ export class BatchPresenter extends BasePresenter {
9697 updatedAt : batch . updatedAt . toISOString ( ) ,
9798 completedAt : batch . completedAt ?. toISOString ( ) ,
9899 processingStartedAt : batch . processingStartedAt ?. toISOString ( ) ,
100+ processingCompletedAt : batch . processingCompletedAt ?. toISOString ( ) ,
99101 finishedAt : batch . completedAt
100102 ? batch . completedAt . toISOString ( )
101103 : hasFinished
Original file line number Diff line number Diff line change @@ -189,6 +189,14 @@ export default function Page() {
189189 </ Property . Value >
190190 </ Property . Item >
191191 ) }
192+ { batch . processingCompletedAt && (
193+ < Property . Item >
194+ < Property . Label > Processing completed</ Property . Label >
195+ < Property . Value >
196+ < DateTime date = { batch . processingCompletedAt } />
197+ </ Property . Value >
198+ </ Property . Item >
199+ ) }
192200 < Property . Item >
193201 < Property . Label > Finished</ Property . Label >
194202 < Property . Value >
Original file line number Diff line number Diff line change @@ -36,17 +36,21 @@ export const loader = createLoaderApiRoute(
3636 idempotencyKey : batch . idempotencyKey ?? undefined ,
3737 createdAt : batch . createdAt ,
3838 updatedAt : batch . updatedAt ,
39+ processingCompletedAt : batch . processingCompletedAt ?? undefined ,
3940 runCount : batch . runCount ,
4041 runs : batch . runIds ,
41- processingErrors :
42- batch . errors . length > 0
43- ? batch . errors . map ( ( err ) => ( {
44- index : err . index ,
45- taskIdentifier : err . taskIdentifier ,
46- error : err . error ,
47- errorCode : err . errorCode ?? undefined ,
48- } ) )
49- : undefined ,
42+ processing : {
43+ completedAt : batch . processingCompletedAt ?? undefined ,
44+ errors :
45+ batch . errors . length > 0
46+ ? batch . errors . map ( ( err ) => ( {
47+ index : err . index ,
48+ taskIdentifier : err . taskIdentifier ,
49+ error : err . error ,
50+ errorCode : err . errorCode ?? undefined ,
51+ } ) )
52+ : [ ] ,
53+ } ,
5054 } ) ;
5155 }
5256) ;
Original file line number Diff line number Diff line change @@ -312,6 +312,7 @@ function setupBatchQueueCallbacks(engine: RunEngine) {
312312 successfulRunCount,
313313 failedRunCount,
314314 completedAt : status === "ABORTED" ? new Date ( ) : undefined ,
315+ processingCompletedAt : new Date ( ) ,
315316 } ,
316317 } ) ;
317318
Original file line number Diff line number Diff line change 1+ -- AlterTable
2+ ALTER TABLE " public" ." BatchTaskRun" ADD COLUMN " processingCompletedAt" TIMESTAMP (3 );
Original file line number Diff line number Diff line change @@ -1571,13 +1571,15 @@ model BatchTaskRun {
15711571
15721572 // Run Engine v2 batch queue fields
15731573 /// When processing started (status changed to PROCESSING)
1574- processingStartedAt DateTime ?
1574+ processingStartedAt DateTime ?
1575+ /// When processing completed (all items processed)
1576+ processingCompletedAt DateTime ?
15751577 /// Count of successfully created runs
1576- successfulRunCount Int ?
1578+ successfulRunCount Int ?
15771579 /// Count of failed run creations
1578- failedRunCount Int ?
1580+ failedRunCount Int ?
15791581 /// Detailed failure records
1580- errors BatchTaskRunError []
1582+ errors BatchTaskRunError []
15811583
15821584 ///all the below properties are engine v1 only
15831585 items BatchTaskRunItem []
Original file line number Diff line number Diff line change @@ -1219,14 +1219,17 @@ export const RetrieveBatchV2Response = z.object({
12191219 updatedAt : z . coerce . date ( ) ,
12201220 runCount : z . number ( ) ,
12211221 runs : z . array ( z . string ( ) ) ,
1222- processingErrors : z . array (
1223- z . object ( {
1224- index : z . number ( ) ,
1225- taskIdentifier : z . string ( ) ,
1226- error : z . string ( ) ,
1227- errorCode : z . string ( ) . optional ( ) ,
1228- } )
1229- ) ,
1222+ processing : z . object ( {
1223+ completedAt : z . coerce . date ( ) . optional ( ) ,
1224+ errors : z . array (
1225+ z . object ( {
1226+ index : z . number ( ) ,
1227+ taskIdentifier : z . string ( ) ,
1228+ error : z . string ( ) ,
1229+ errorCode : z . string ( ) . optional ( ) ,
1230+ } )
1231+ ) ,
1232+ } ) ,
12301233} ) ;
12311234
12321235export type RetrieveBatchV2Response = z . infer < typeof RetrieveBatchV2Response > ;
Original file line number Diff line number Diff line change @@ -5,12 +5,13 @@ import {
55 ApiRequestOptions ,
66 mergeRequestOptions ,
77 RetrieveBatchResponse ,
8+ RetrieveBatchV2Response ,
89} from "@trigger.dev/core/v3" ;
910import {
11+ batchTriggerAndWaitTasks ,
1012 batchTriggerById ,
1113 batchTriggerByIdAndWait ,
1214 batchTriggerTasks ,
13- batchTriggerAndWaitTasks ,
1415} from "./shared.js" ;
1516import { tracer } from "./tracer.js" ;
1617
@@ -42,7 +43,7 @@ export const batch = {
4243function retrieveBatch (
4344 batchId : string ,
4445 requestOptions ?: ApiRequestOptions
45- ) : ApiPromise < RetrieveBatchResponse > {
46+ ) : ApiPromise < RetrieveBatchV2Response > {
4647 const apiClient = apiClientManager . clientOrThrow ( ) ;
4748
4849 const $requestOptions = mergeRequestOptions (
Original file line number Diff line number Diff line change 1- import { batch , task } from "@trigger.dev/sdk/v3" ;
1+ import { batch , logger , task } from "@trigger.dev/sdk/v3" ;
22import { setTimeout } from "timers/promises" ;
33
44export const batchTriggerAndWait = task ( {
@@ -207,11 +207,17 @@ export const largePayloadBatch = task({
207207 }
208208
209209 // Trigger the batch - large payloads are automatically offloaded to R2
210- const result = await largePayloadTask . batchTriggerAndWait ( generateLargeItems ( ) ) ;
210+ const result = await largePayloadTask . batchTrigger ( generateLargeItems ( ) ) ;
211+
212+ await setTimeout ( 5000 ) ;
213+
214+ const myBatch = await batch . retrieve ( result . batchId ) ;
215+
216+ logger . info ( "batch" , { myBatch } ) ;
211217
212218 return {
213- batchId : result . id ,
214- runCount : result . runs . length ,
219+ batchId : result . batchId ,
220+ runCount : result . runCount ,
215221 payloadSizeKB : sizeKB ,
216222 note : `Each payload was ~${ sizeKB } KB. Payloads over 512KB are offloaded to R2.` ,
217223 } ;
You can’t perform that action at this time.
0 commit comments