Skip to content

Commit 970c41c

Browse files
committed
fix: comments
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent ba7b467 commit 970c41c

4 files changed

Lines changed: 20 additions & 9 deletions

File tree

backend/src/api/public/v1/akrites-external/openapi.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,9 @@ components:
458458
type: object
459459
required: [results]
460460
description: >
461-
Plain array in request order, one entry per submitted job — unlike the
462-
read batches there is no found/not-found case, every job is submitted.
461+
Plain array in request order, one entry per requested job — unlike the
462+
read batches there is no found/not-found case, but a job can still come
463+
back with status: failed if row creation or the workflow start failed.
463464
properties:
464465
results:
465466
type: array

backend/src/api/public/v1/packages/submitBlastRadiusJobBatch.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { Request, Response } from 'express'
33
import { generateUUIDv4 } from '@crowd/common'
44
import * as blastRadiusDal from '@crowd/data-access-layer/src/packages/blastRadius'
55
import { QueryExecutor } from '@crowd/data-access-layer/src/queryExecutor'
6-
import { Client } from '@crowd/temporal'
76
import { ITriggerBlastRadiusAnalysis, TemporalWorkflowId } from '@crowd/types'
87

98
import { 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

4442
async 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}`,

services/apps/packages_worker/src/blast-radius/dependentsScan.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import { rangeIncludesAny } from './semverRange'
1313

1414
// Configurable via env var so local load tests can vary it per run without
1515
// editing source; unset in every real deployment, so this is always 32 in prod.
16-
const SCAN_CONCURRENCY = Number(process.env.BLAST_RADIUS_SCAN_CONCURRENCY) || 32
16+
// Clamped to a positive integer — a negative or fractional override would make
17+
// forEachWithConcurrency's Array.from({length: concurrency}) spin up zero workers,
18+
// so the scan would silently complete with nothing processed.
19+
const SCAN_CONCURRENCY =
20+
Math.max(1, Math.floor(Number(process.env.BLAST_RADIUS_SCAN_CONCURRENCY))) || 32
1721
const HIGH_IMPACT_CACHE_TTL_MS = 24 * 60 * 60 * 1000
1822
// The per-candidate fetches below (abbreviated packument, full packument, download count)
1923
// don't depend on which target package the analysis is checking against — the same

services/apps/packages_worker/src/blast-radius/stages/reachability.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ const mkdtemp = promisify(fs.mkdtemp)
2121
const MAX_ATTEMPTS = 3
2222
const RETRY_BACKOFF_BASE = 15_000 // 15 seconds
2323
// Tunable for load testing, same pattern as BLAST_RADIUS_SCAN_CONCURRENCY for phase 1/2 —
24-
// default matches the previous hardcoded value.
25-
const REACHABILITY_CONCURRENCY = Number(process.env.BLAST_RADIUS_REACHABILITY_CONCURRENCY) || 4
24+
// default matches the previous hardcoded value. Clamped to a positive integer for the
25+
// same reason (see dependentsScan.ts's SCAN_CONCURRENCY): a negative/fractional override
26+
// would make forEachWithConcurrency spin up zero workers and silently skip all work.
27+
const REACHABILITY_CONCURRENCY =
28+
Math.max(1, Math.floor(Number(process.env.BLAST_RADIUS_REACHABILITY_CONCURRENCY))) || 4
2629

2730
// blastRadiusDal.getSymbolSpec returns the raw DB row (JSONB columns as
2831
// unknown); prompts.ts's SymbolSpec is the shape the reachability prompt

0 commit comments

Comments
 (0)