|
1 | 1 | import { ScheduleAlreadyRunning, ScheduleOverlapPolicy } from '@temporalio/client' |
2 | 2 |
|
3 | 3 | import { svc } from '../service' |
4 | | -import { mavenCriticalWorkflow } from '../workflows' |
| 4 | +import { ingestMavenPackages } from '../workflows' |
5 | 5 |
|
6 | | -export async function scheduleMavenCritical(): Promise<void> { |
| 6 | +const LEGACY_SCHEDULE_ID = 'maven-critical' |
| 7 | + |
| 8 | +export async function scheduleMavenIngestion(): Promise<void> { |
7 | 9 | const { temporal } = svc |
8 | 10 | if (!temporal) throw new Error('Temporal client not initialized') |
9 | 11 |
|
10 | | - const scheduleOptions: Parameters<typeof temporal.schedule.create>[0] = { |
11 | | - scheduleId: 'maven-critical', |
12 | | - spec: { |
13 | | - cronExpressions: ['*/1 * * * *'], |
14 | | - }, |
15 | | - policies: { |
16 | | - overlap: ScheduleOverlapPolicy.SKIP, |
17 | | - catchupWindow: '1 hour', |
18 | | - }, |
19 | | - action: { |
20 | | - type: 'startWorkflow', |
21 | | - workflowType: mavenCriticalWorkflow, |
22 | | - taskQueue: 'packages-worker', |
23 | | - workflowExecutionTimeout: '15 minutes', |
24 | | - retry: { |
25 | | - initialInterval: '30 seconds', |
26 | | - backoffCoefficient: 2, |
27 | | - maximumAttempts: 3, |
28 | | - }, |
29 | | - args: [], |
30 | | - }, |
| 12 | + try { |
| 13 | + await temporal.schedule.getHandle(LEGACY_SCHEDULE_ID).delete() |
| 14 | + svc.log.info({ scheduleId: LEGACY_SCHEDULE_ID }, 'Deleted legacy schedule.') |
| 15 | + } catch (err) { |
| 16 | + svc.log.warn( |
| 17 | + { err, scheduleId: LEGACY_SCHEDULE_ID }, |
| 18 | + 'Failed to delete legacy schedule (may not exist).', |
| 19 | + ) |
31 | 20 | } |
32 | 21 |
|
33 | 22 | try { |
34 | | - await temporal.schedule.create(scheduleOptions) |
| 23 | + await temporal.schedule.create({ |
| 24 | + scheduleId: 'maven-ingestion', |
| 25 | + spec: { |
| 26 | + cronExpressions: ['0 9 * * *'], |
| 27 | + }, |
| 28 | + policies: { |
| 29 | + overlap: ScheduleOverlapPolicy.SKIP, |
| 30 | + catchupWindow: '1 hour', |
| 31 | + }, |
| 32 | + action: { |
| 33 | + type: 'startWorkflow', |
| 34 | + workflowType: ingestMavenPackages, |
| 35 | + workflowId: 'maven-daily-enrichment', |
| 36 | + taskQueue: 'packages-worker', |
| 37 | + workflowRunTimeout: '24 hours', |
| 38 | + retry: { |
| 39 | + initialInterval: '30 seconds', |
| 40 | + backoffCoefficient: 2, |
| 41 | + maximumAttempts: 3, |
| 42 | + }, |
| 43 | + args: [], |
| 44 | + }, |
| 45 | + }) |
35 | 46 | } catch (err) { |
36 | 47 | if (err instanceof ScheduleAlreadyRunning) { |
37 | | - svc.log.info('Schedule maven-critical already exists, skipping creation.') |
| 48 | + svc.log.info('Schedule maven-ingestion already exists, skipping creation.') |
38 | 49 | } else { |
39 | 50 | throw err |
40 | 51 | } |
41 | 52 | } |
42 | 53 | } |
43 | | - |
44 | | -// export async function scheduleMavenNonCritical(): Promise<void> { |
45 | | -// const { temporal } = svc |
46 | | -// if (!temporal) throw new Error('Temporal client not initialized') |
47 | | - |
48 | | -// try { |
49 | | -// await temporal.schedule.create({ |
50 | | -// scheduleId: 'maven-non-critical', |
51 | | -// spec: { |
52 | | -// cronExpressions: ['*/10 * * * *'], |
53 | | -// }, |
54 | | -// policies: { |
55 | | -// overlap: ScheduleOverlapPolicy.SKIP, |
56 | | -// catchupWindow: '1 hour', |
57 | | -// }, |
58 | | -// action: { |
59 | | -// type: 'startWorkflow', |
60 | | -// workflowType: mavenNonCriticalWorkflow, |
61 | | -// taskQueue: 'packages-worker', |
62 | | -// workflowExecutionTimeout: '5 minutes', |
63 | | -// retry: { |
64 | | -// initialInterval: '30 seconds', |
65 | | -// backoffCoefficient: 2, |
66 | | -// maximumAttempts: 3, |
67 | | -// }, |
68 | | -// args: [], |
69 | | -// }, |
70 | | -// }) |
71 | | -// } catch (err) { |
72 | | -// if (err instanceof ScheduleAlreadyRunning) { |
73 | | -// svc.log.info('Schedule maven-non-critical already registered.') |
74 | | -// } else { |
75 | | -// throw err |
76 | | -// } |
77 | | -// } |
78 | | -// } |
0 commit comments