@@ -27,7 +27,7 @@ import { PerformTaskRunAlertsService } from "./services/alerts/performTaskRunAle
2727import { TaskRunErrorCodes } from "@trigger.dev/core/v3" ;
2828
2929export function registerRunEngineEventBusHandlers ( ) {
30- engine . eventBus . on ( "runSucceeded" , async ( { time, run } ) => {
30+ engine . eventBus . on ( "runSucceeded" , async ( { time, run, organization } ) => {
3131 const [ taskRunError , taskRun ] = await tryCatch (
3232 $replica . taskRun . findFirstOrThrow ( {
3333 where : {
@@ -60,7 +60,10 @@ export function registerRunEngineEventBusHandlers() {
6060 return ;
6161 }
6262
63- const eventRepository = resolveEventRepositoryForStore ( run . taskEventStore ) ;
63+ const eventRepository = resolveEventRepositoryForStore (
64+ run . taskEventStore ,
65+ taskRun . organizationId ?? organization . id
66+ ) ;
6467
6568 const [ completeSuccessfulRunEventError ] = await tryCatch (
6669 eventRepository . completeSuccessfulRunEvent ( {
@@ -91,7 +94,7 @@ export function registerRunEngineEventBusHandlers() {
9194 } ) ;
9295
9396 // Handle events
94- engine . eventBus . on ( "runFailed" , async ( { time, run } ) => {
97+ engine . eventBus . on ( "runFailed" , async ( { time, run, organization } ) => {
9598 const sanitizedError = sanitizeError ( run . error ) ;
9699 const exception = createExceptionPropertiesFromError ( sanitizedError ) ;
97100
@@ -127,7 +130,10 @@ export function registerRunEngineEventBusHandlers() {
127130 return ;
128131 }
129132
130- const eventRepository = resolveEventRepositoryForStore ( taskRun . taskEventStore ) ;
133+ const eventRepository = resolveEventRepositoryForStore (
134+ run . taskEventStore ,
135+ taskRun . organizationId ?? organization . id
136+ ) ;
131137
132138 const [ completeFailedRunEventError ] = await tryCatch (
133139 eventRepository . completeFailedRunEvent ( {
@@ -181,7 +187,10 @@ export function registerRunEngineEventBusHandlers() {
181187 return ;
182188 }
183189
184- const eventRepository = resolveEventRepositoryForStore ( taskRun . taskEventStore ) ;
190+ const eventRepository = resolveEventRepositoryForStore (
191+ run . taskEventStore ,
192+ taskRun . organizationId ?? ""
193+ ) ;
185194
186195 const [ createAttemptFailedRunEventError ] = await tryCatch (
187196 eventRepository . createAttemptFailedRunEvent ( {
@@ -282,7 +291,10 @@ export function registerRunEngineEventBusHandlers() {
282291 return ;
283292 }
284293
285- const eventRepository = resolveEventRepositoryForStore ( blockedRun . taskEventStore ) ;
294+ const eventRepository = resolveEventRepositoryForStore (
295+ blockedRun . taskEventStore ,
296+ blockedRun . organizationId ?? ""
297+ ) ;
286298
287299 const [ completeCachedRunEventError ] = await tryCatch (
288300 eventRepository . completeCachedRunEvent ( {
@@ -305,7 +317,7 @@ export function registerRunEngineEventBusHandlers() {
305317 }
306318 ) ;
307319
308- engine . eventBus . on ( "runExpired" , async ( { time, run } ) => {
320+ engine . eventBus . on ( "runExpired" , async ( { time, run, organization } ) => {
309321 if ( ! run . ttl ) {
310322 return ;
311323 }
@@ -342,7 +354,10 @@ export function registerRunEngineEventBusHandlers() {
342354 return ;
343355 }
344356
345- const eventRepository = resolveEventRepositoryForStore ( taskRun . taskEventStore ) ;
357+ const eventRepository = resolveEventRepositoryForStore (
358+ taskRun . taskEventStore ,
359+ taskRun . organizationId ?? organization . id
360+ ) ;
346361
347362 const [ completeExpiredRunEventError ] = await tryCatch (
348363 eventRepository . completeExpiredRunEvent ( {
@@ -360,7 +375,7 @@ export function registerRunEngineEventBusHandlers() {
360375 }
361376 } ) ;
362377
363- engine . eventBus . on ( "runCancelled" , async ( { time, run } ) => {
378+ engine . eventBus . on ( "runCancelled" , async ( { time, run, organization } ) => {
364379 const [ taskRunError , taskRun ] = await tryCatch (
365380 $replica . taskRun . findFirstOrThrow ( {
366381 where : {
@@ -393,7 +408,10 @@ export function registerRunEngineEventBusHandlers() {
393408 return ;
394409 }
395410
396- const eventRepository = resolveEventRepositoryForStore ( taskRun . taskEventStore ) ;
411+ const eventRepository = resolveEventRepositoryForStore (
412+ taskRun . taskEventStore ,
413+ taskRun . organizationId ?? organization . id
414+ ) ;
397415
398416 const error = createJsonErrorObject ( run . error ) ;
399417
@@ -413,7 +431,7 @@ export function registerRunEngineEventBusHandlers() {
413431 }
414432 } ) ;
415433
416- engine . eventBus . on ( "runRetryScheduled" , async ( { time, run, environment, retryAt } ) => {
434+ engine . eventBus . on ( "runRetryScheduled" , async ( { time, run, environment, retryAt, organization } ) => {
417435 try {
418436 if ( retryAt && time && time >= retryAt ) {
419437 return ;
@@ -426,7 +444,10 @@ export function registerRunEngineEventBusHandlers() {
426444 retryMessage += ` after OOM` ;
427445 }
428446
429- const eventRepository = resolveEventRepositoryForStore ( run . taskEventStore ) ;
447+ const eventRepository = resolveEventRepositoryForStore (
448+ run . taskEventStore ?? "taskEvent" ,
449+ organization . id
450+ ) ;
430451
431452 await eventRepository . recordEvent ( retryMessage , {
432453 startTime : BigInt ( time . getTime ( ) * 1000000 ) ,
0 commit comments