|
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' |
2 | 9 |
|
3 | 10 | import type * as activities from './activities' |
4 | 11 | import { INGEST_MAX_ATTEMPTS } from './retryPolicy' |
@@ -30,10 +37,25 @@ export async function seedPackagistPackages(): Promise<void> { |
30 | 37 | // discovered packages are rows before the p2 crawl resolves dependency targets. |
31 | 38 | // Started (not awaited) with ABANDON — the drain runs for hours and must outlive |
32 | 39 | // 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 | + } |
37 | 59 | } |
38 | 60 |
|
39 | 61 | export async function ingestPackagistMetadata(state: MetadataState = {}): Promise<void> { |
|
0 commit comments