Skip to content

Commit 25677f0

Browse files
committed
fix: guard packagist metadata drain against overlap
Signed-off-by: anilb <epipav@gmail.com>
1 parent 5e0b9a0 commit 25677f0

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

services/apps/packages_worker/src/packagist/workflows.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { ParentClosePolicy, continueAsNew, proxyActivities, startChild } from '@temporalio/workflow'
1+
import {
2+
ParentClosePolicy,
3+
WorkflowIdReusePolicy,
4+
continueAsNew,
5+
log,
6+
proxyActivities,
7+
startChild,
8+
} from '@temporalio/workflow'
29

310
import type * as activities from './activities'
411
import { INGEST_MAX_ATTEMPTS } from './retryPolicy'
@@ -30,10 +37,25 @@ export async function seedPackagistPackages(): Promise<void> {
3037
// discovered packages are rows before the p2 crawl resolves dependency targets.
3138
// Started (not awaited) with ABANDON — the drain runs for hours and must outlive
3239
// this workflow; the state watermarks make the pass self-advancing regardless.
33-
await startChild(ingestPackagistMetadata, {
34-
args: [{}],
35-
parentClosePolicy: ParentClosePolicy.ABANDON,
36-
})
40+
// Fixed workflowId + ALLOW_DUPLICATE: starting a duplicate against a still-RUNNING
41+
// execution with the same id always throws WorkflowExecutionAlreadyStartedError
42+
// regardless of reuse policy, so a drain that outlasts the week makes next
43+
// Sunday's seed skip its chain-start instead of doubling the crawl; ALLOW_DUPLICATE
44+
// just lets the id be reused once that prior execution has actually closed.
45+
try {
46+
await startChild(ingestPackagistMetadata, {
47+
workflowId: 'packagist-metadata-drain',
48+
workflowIdReusePolicy: WorkflowIdReusePolicy.ALLOW_DUPLICATE,
49+
args: [{}],
50+
parentClosePolicy: ParentClosePolicy.ABANDON,
51+
})
52+
} catch (err) {
53+
if (err instanceof Error && err.name === 'WorkflowExecutionAlreadyStartedError') {
54+
log.warn('packagist metadata drain still running from a prior seed — skipping chain-start')
55+
return
56+
}
57+
throw err
58+
}
3759
}
3860

3961
export async function ingestPackagistMetadata(state: MetadataState = {}): Promise<void> {

0 commit comments

Comments
 (0)