Skip to content

Commit f1eb31b

Browse files
committed
Merge branch 'main' into test-kit-primitives
2 parents b2aca6e + a4d2422 commit f1eb31b

11 files changed

Lines changed: 1396 additions & 37 deletions

File tree

services/apps/packages_worker/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
"dev:rubygems-worker:local": "set -a && . ../../../backend/.env.dist.local && . ../../../backend/.env.override.local && set +a && CROWD_TEMPORAL_TASKQUEUE=rubygems-worker SERVICE=rubygems-worker LOG_LEVEL=trace nodemon --watch src --watch ../../libs --ext ts --exec tsx --inspect=0.0.0.0:9244 src/bin/rubygems-worker.ts",
5555
"backfill:maven": "SERVICE=maven tsx src/bin/maven-backfill.ts",
5656
"backfill:maven:local": "set -a && . ../../../backend/.env.dist.local && . ../../../backend/.env.override.local && set +a && SERVICE=maven LOG_LEVEL=info tsx src/bin/maven-backfill.ts",
57+
"backfill:maven-repo-url": "SERVICE=maven tsx src/bin/maven-repo-url-backfill.ts",
58+
"backfill:maven-repo-url:local": "set -a && . ../../../backend/.env.dist.local && . ../../../backend/.env.override.local && set +a && SERVICE=maven LOG_LEVEL=info tsx src/bin/maven-repo-url-backfill.ts",
5759
"import:maven-maintainers": "SERVICE=maven tsx src/maven/scripts/importMaintainersFromCsv.ts",
5860
"import:maven-maintainers:local": "set -a && . ../../../backend/.env.dist.local && . ../../../backend/.env.override.local && set +a && SERVICE=maven tsx src/maven/scripts/importMaintainersFromCsv.ts",
5961
"import:sonatype-popularity": "SERVICE=maven tsx src/maven/scripts/importSonatypePopularityFromCsv.ts",

services/apps/packages_worker/src/bin/maven-backfill.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { getServiceLogger } from '@crowd/logging'
22

33
import { getMavenConfig } from '../config'
44
import { getPackagesDb } from '../db'
5-
import { runMavenCriticalBackfill } from '../maven/runMavenEnrichmentLoop'
5+
import {
6+
runMavenCriticalBackfill,
7+
runMavenCriticalForceBackfill,
8+
} from '../maven/runMavenEnrichmentLoop'
69

710
const log = getServiceLogger()
811

@@ -25,7 +28,14 @@ const main = async () => {
2528
process.env.MAVEN_FETCHER_BASE_URL_BACKFILL ??
2629
'https://maven-central.storage-download.googleapis.com/maven2'
2730

28-
log.info('maven backfill starting (one-shot, full extraction)...')
31+
// --force: re-run POM extraction over EVERY critical row, ignoring the
32+
// staleness window. Use to fully re-apply extraction changes (e.g. SCM
33+
// interpolation) after the queue has already drained. The default path only
34+
// picks rows due by refreshDays and cannot be coaxed into a full pass by
35+
// setting refreshDays=0 (that reprocesses the first batch forever).
36+
const force = process.argv.includes('--force')
37+
38+
log.info({ force }, 'maven backfill starting (one-shot, full extraction)...')
2939

3040
const config = getMavenConfig()
3141
log.info(config, 'Config loaded')
@@ -34,7 +44,9 @@ const main = async () => {
3444
await qx.selectOne('SELECT 1')
3545
log.info('Connected to packages-db.')
3646

37-
const totals = await runMavenCriticalBackfill(qx, config, () => shuttingDown)
47+
const totals = force
48+
? await runMavenCriticalForceBackfill(qx, config, () => shuttingDown)
49+
: await runMavenCriticalBackfill(qx, config, () => shuttingDown)
3850

3951
log.info({ ...totals }, 'maven backfill complete')
4052
process.exit(0)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { getServiceLogger } from '@crowd/logging'
2+
3+
import { getPackagesDb } from '../db'
4+
import { backfillMavenRepositoryUrls } from '../maven/backfillRepositoryUrl'
5+
6+
const log = getServiceLogger()
7+
8+
let shuttingDown = false
9+
10+
// Graceful stop: finish the in-flight batch, then exit. Safe to interrupt — every
11+
// write is an idempotent UPDATE recomputed from declared_repository_url, so
12+
// re-running simply reprocesses and skips rows that already match.
13+
const shutdown = () => {
14+
if (shuttingDown) return
15+
shuttingDown = true
16+
log.info('Shutting down maven repo-url backfill (stopping after the current batch)...')
17+
}
18+
19+
process.on('SIGINT', shutdown)
20+
process.on('SIGTERM', shutdown)
21+
22+
const DEFAULT_BATCH_SIZE = 5000
23+
24+
const main = async () => {
25+
const dryRun = process.argv.includes('--dry-run')
26+
const criticalOnly = process.argv.includes('--critical-only')
27+
const rawBatchSize = process.env.MAVEN_REPO_URL_BACKFILL_BATCH_SIZE
28+
const parsedBatchSize = rawBatchSize === undefined ? DEFAULT_BATCH_SIZE : Number(rawBatchSize)
29+
if (!Number.isInteger(parsedBatchSize) || parsedBatchSize <= 0) {
30+
log.error(
31+
{ MAVEN_REPO_URL_BACKFILL_BATCH_SIZE: rawBatchSize },
32+
'MAVEN_REPO_URL_BACKFILL_BATCH_SIZE must be a positive integer',
33+
)
34+
process.exit(1)
35+
}
36+
const batchSize = parsedBatchSize
37+
38+
log.info(
39+
{ dryRun, criticalOnly, batchSize },
40+
'maven repo-url backfill starting (recompute normalizeScmUrl from declared_repository_url, no POM fetch)...',
41+
)
42+
43+
const qx = await getPackagesDb()
44+
await qx.selectOne('SELECT 1')
45+
log.info('Connected to packages-db.')
46+
47+
const totals = await backfillMavenRepositoryUrls(qx, {
48+
batchSize,
49+
dryRun,
50+
criticalOnly,
51+
isShuttingDown: () => shuttingDown,
52+
})
53+
54+
log.info({ ...totals, dryRun }, 'maven repo-url backfill complete')
55+
process.exit(0)
56+
}
57+
58+
main().catch((err) => {
59+
log.error({ err }, 'maven repo-url backfill fatal error')
60+
process.exit(1)
61+
})

0 commit comments

Comments
 (0)