Skip to content

Commit 5e5c010

Browse files
committed
fix: comments review
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent 2441129 commit 5e5c010

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

services/apps/packages_worker/src/maven/backfillRepositoryUrl.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { QueryExecutor } from '@crowd/data-access-layer/src/queryExecutor'
77
import { getServiceChildLogger } from '@crowd/logging'
88

99
import { normalizeScmUrl } from './extract'
10-
import { writeRepoLink } from './runMavenEnrichmentLoop'
10+
import { withDeadlockRetry, writeRepoLink } from './runMavenEnrichmentLoop'
1111

1212
const log = getServiceChildLogger('maven-repo-url-backfill')
1313

@@ -102,13 +102,15 @@ export async function backfillMavenRepositoryUrls(
102102
// re-run the row is skipped (its repository_url already matches `desired`),
103103
// so the inconsistency would never be repaired. On rollback the row stays
104104
// unchanged and is reprocessed on the next run.
105-
await qx.tx(async (t) => {
106-
await updateMavenRepositoryUrls(t, updates)
107-
await deleteMavenPackageRepoLinks(t, pruneTargets)
108-
for (const target of linkTargets) {
109-
await writeRepoLink(t, target.id, target.repositoryUrl)
110-
}
111-
})
105+
await withDeadlockRetry(() =>
106+
qx.tx(async (t) => {
107+
await updateMavenRepositoryUrls(t, updates)
108+
await deleteMavenPackageRepoLinks(t, pruneTargets)
109+
for (const target of linkTargets) {
110+
await writeRepoLink(t, target.id, target.repositoryUrl)
111+
}
112+
}),
113+
)
112114
totals.pruned += pruneTargets.length
113115
totals.linked += linkTargets.length
114116
}

services/apps/packages_worker/src/maven/runMavenEnrichmentLoop.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export async function writeRepoLink(qx: QueryExecutor, packageId: number, reposi
7272
// rows (e.g. maintainer 'hboutemy' across many org.apache packages, or the shared apache repo)
7373
// can form a lock cycle. Re-running the whole transaction resolves it — the upserts are idempotent.
7474
// prettier-ignore
75-
async function withDeadlockRetry<T>(fn: () => Promise<T>, maxAttempts = 4): Promise<T> {
75+
export async function withDeadlockRetry<T>(fn: () => Promise<T>, maxAttempts = 4): Promise<T> {
7676
for (let attempt = 1; ; attempt++) {
7777
try {
7878
return await fn()

0 commit comments

Comments
 (0)