Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions services/apps/packages_worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
"dev:nuget-worker:local": "set -a && . ../../../backend/.env.dist.local && . ../../../backend/.env.override.local && set +a && CROWD_TEMPORAL_TASKQUEUE=nuget-worker SERVICE=nuget-worker LOG_LEVEL=trace nodemon --watch src --watch ../../libs --ext ts --exec tsx --inspect=0.0.0.0:9242 src/bin/nuget-worker.ts",
"backfill:maven": "SERVICE=maven tsx src/bin/maven-backfill.ts",
"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",
"backfill:maven-repo-url": "SERVICE=maven tsx src/bin/maven-repo-url-backfill.ts",
"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",
"import:maven-maintainers": "SERVICE=maven tsx src/maven/scripts/importMaintainersFromCsv.ts",
"import:maven-maintainers:local": "set -a && . ../../../backend/.env.dist.local && . ../../../backend/.env.override.local && set +a && SERVICE=maven tsx src/maven/scripts/importMaintainersFromCsv.ts",
"import:sonatype-popularity": "SERVICE=maven tsx src/maven/scripts/importSonatypePopularityFromCsv.ts",
Expand Down
18 changes: 15 additions & 3 deletions services/apps/packages_worker/src/bin/maven-backfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { getServiceLogger } from '@crowd/logging'

import { getMavenConfig } from '../config'
import { getPackagesDb } from '../db'
import { runMavenCriticalBackfill } from '../maven/runMavenEnrichmentLoop'
import {
runMavenCriticalBackfill,
runMavenCriticalForceBackfill,
} from '../maven/runMavenEnrichmentLoop'

const log = getServiceLogger()

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

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

log.info({ force }, 'maven backfill starting (one-shot, full extraction)...')

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

const totals = await runMavenCriticalBackfill(qx, config, () => shuttingDown)
const totals = force
? await runMavenCriticalForceBackfill(qx, config, () => shuttingDown)
: await runMavenCriticalBackfill(qx, config, () => shuttingDown)

log.info({ ...totals }, 'maven backfill complete')
process.exit(0)
Expand Down
61 changes: 61 additions & 0 deletions services/apps/packages_worker/src/bin/maven-repo-url-backfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { getServiceLogger } from '@crowd/logging'

import { getPackagesDb } from '../db'
import { backfillMavenRepositoryUrls } from '../maven/backfillRepositoryUrl'

const log = getServiceLogger()

let shuttingDown = false

// Graceful stop: finish the in-flight batch, then exit. Safe to interrupt — every
// write is an idempotent UPDATE recomputed from declared_repository_url, so
// re-running simply reprocesses and skips rows that already match.
const shutdown = () => {
if (shuttingDown) return
shuttingDown = true
log.info('Shutting down maven repo-url backfill (stopping after the current batch)...')
}

process.on('SIGINT', shutdown)
process.on('SIGTERM', shutdown)

const DEFAULT_BATCH_SIZE = 5000

const main = async () => {
const dryRun = process.argv.includes('--dry-run')
const criticalOnly = process.argv.includes('--critical-only')
const rawBatchSize = process.env.MAVEN_REPO_URL_BACKFILL_BATCH_SIZE
const parsedBatchSize = rawBatchSize === undefined ? DEFAULT_BATCH_SIZE : Number(rawBatchSize)
if (!Number.isInteger(parsedBatchSize) || parsedBatchSize <= 0) {
log.error(
{ MAVEN_REPO_URL_BACKFILL_BATCH_SIZE: rawBatchSize },
'MAVEN_REPO_URL_BACKFILL_BATCH_SIZE must be a positive integer',
)
process.exit(1)
}
const batchSize = parsedBatchSize

log.info(
{ dryRun, criticalOnly, batchSize },
'maven repo-url backfill starting (recompute normalizeScmUrl from declared_repository_url, no POM fetch)...',
)

const qx = await getPackagesDb()
await qx.selectOne('SELECT 1')
log.info('Connected to packages-db.')

const totals = await backfillMavenRepositoryUrls(qx, {
batchSize,
dryRun,
criticalOnly,
isShuttingDown: () => shuttingDown,
})

log.info({ ...totals, dryRun }, 'maven repo-url backfill complete')
process.exit(0)
}

main().catch((err) => {
log.error({ err }, 'maven repo-url backfill fatal error')
process.exit(1)
})
Loading
Loading