@@ -3,7 +3,6 @@ import type { Request, Response } from 'express'
33import { generateUUIDv4 } from '@crowd/common'
44import * as blastRadiusDal from '@crowd/data-access-layer/src/packages/blastRadius'
55import { QueryExecutor } from '@crowd/data-access-layer/src/queryExecutor'
6- import { Client } from '@crowd/temporal'
76import { ITriggerBlastRadiusAnalysis , TemporalWorkflowId } from '@crowd/types'
87
98import { getPackagesQx } from '@/db/packagesDb'
@@ -32,18 +31,16 @@ export async function submitBlastRadiusJobBatch(req: Request, res: Response): Pr
3231 const { jobs } = validateOrThrow ( blastRadiusJobBatchRequestSchema , req . body )
3332
3433 const qx = await getPackagesQx ( )
35- const packagesTemporal = await getPackagesTemporalClient ( )
3634
3735 const results : BlastRadiusJobEntry [ ] = await Promise . all (
38- jobs . map ( ( body ) => submitOneJob ( qx , packagesTemporal , body ) ) ,
36+ jobs . map ( ( body ) => submitOneJob ( qx , body ) ) ,
3937 )
4038
4139 res . status ( 202 ) . json ( { results } )
4240}
4341
4442async function submitOneJob (
4543 qx : QueryExecutor ,
46- packagesTemporal : Client ,
4744 body : BlastRadiusJobRequest ,
4845) : Promise < BlastRadiusJobEntry > {
4946 const jobPackage = body . package ?? null
@@ -64,6 +61,12 @@ async function submitOneJob(
6461 // must not reject the whole batch's Promise.all, only this job's entry.
6562 await blastRadiusDal . createAnalysis ( qx , analysisInput )
6663
64+ // Acquired per job (inside the try), not once up front — getPackagesTemporalClient
65+ // caches its connection in a module-level singleton, so this is cheap once
66+ // connected, but a first-ever connection failure must fail this job's entry only,
67+ // not reject the whole batch before any per-job try/catch is in play.
68+ const packagesTemporal = await getPackagesTemporalClient ( )
69+
6770 await packagesTemporal . workflow . start ( 'analyzeBlastRadius' , {
6871 taskQueue : 'blast-radius-worker' ,
6972 workflowId : `${ TemporalWorkflowId . BLAST_RADIUS_ANALYSIS } /${ analysisId } ` ,
0 commit comments