Skip to content

Commit cb69984

Browse files
committed
feat: add npm-registry-ingest daily schedule
Signed-off-by: anilb <epipav@gmail.com>
1 parent 21388b8 commit cb69984

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { scheduleNpmIngest } from '../npm/schedule'
12
import { svc } from '../service'
23

34
setImmediate(async () => {
45
await svc.init()
6+
await scheduleNpmIngest()
57
await svc.start()
68
})
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { ScheduleAlreadyRunning, ScheduleOverlapPolicy } from '@temporalio/client'
2+
3+
import { svc } from '../service'
4+
5+
import { npmHello } from './workflows'
6+
7+
export async function scheduleNpmIngest(): Promise<void> {
8+
const { temporal } = svc
9+
if (!temporal) throw new Error('Temporal client not initialized')
10+
11+
try {
12+
await temporal.schedule.create({
13+
scheduleId: 'npm-registry-ingest',
14+
spec: {
15+
cronExpressions: ['15 3 * * *'],
16+
},
17+
policies: {
18+
overlap: ScheduleOverlapPolicy.SKIP,
19+
catchupWindow: '1 hour',
20+
},
21+
action: {
22+
type: 'startWorkflow',
23+
workflowType: npmHello,
24+
taskQueue: 'packages-worker',
25+
workflowExecutionTimeout: '1 hour',
26+
retry: {
27+
initialInterval: '30 seconds',
28+
backoffCoefficient: 2,
29+
maximumAttempts: 3,
30+
},
31+
args: [],
32+
},
33+
})
34+
} catch (err) {
35+
if (err instanceof ScheduleAlreadyRunning) {
36+
svc.log.info('Schedule npm-registry-ingest already registered.')
37+
} else {
38+
throw err
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)