Skip to content

Commit 1bba738

Browse files
committed
add retries to populateActivityRelations workflow using schedules
1 parent 675e974 commit 1bba738

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/apps/script_executor_worker/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020
"@crowd/opensearch": "workspace:*",
2121
"@crowd/redis": "workspace:*",
2222
"@crowd/types": "workspace:*",
23-
"@crowd/common": "workspace:*",
24-
"@crowd/opensearch": "workspace:*",
2523
"@temporalio/workflow": "~1.11.1",
24+
"@temporalio/client": "~1.11.1",
2625
"axios": "^1.6.8",
2726
"moment": "~2.29.4",
2827
"tsx": "^4.7.1",
@@ -32,4 +31,4 @@
3231
"@types/node": "^20.8.2",
3332
"nodemon": "^3.0.1"
3433
}
35-
}
34+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { ScheduleAlreadyRunning, ScheduleOverlapPolicy } from '@temporalio/client'
2+
3+
import { svc } from '../main'
4+
import { populateActivityRelations } from '../workflows'
5+
6+
export const schedulePopulateActivityRelations = async () => {
7+
try {
8+
await svc.temporal.schedule.create({
9+
scheduleId: 'populateActivityRelations',
10+
spec: {
11+
cronExpressions: ['30 0 * * *'],
12+
},
13+
policies: {
14+
overlap: ScheduleOverlapPolicy.BUFFER_ONE,
15+
catchupWindow: '1 minute',
16+
},
17+
action: {
18+
type: 'startWorkflow',
19+
workflowType: populateActivityRelations,
20+
taskQueue: 'script-executor',
21+
retry: {
22+
initialInterval: '15 seconds',
23+
backoffCoefficient: 2,
24+
maximumAttempts: 3,
25+
},
26+
args: [
27+
{
28+
batchSizePerRun: 10000,
29+
deleteIndexedEntities: false,
30+
},
31+
],
32+
},
33+
})
34+
} catch (err) {
35+
if (err instanceof ScheduleAlreadyRunning) {
36+
svc.log.info('Schedule already registered in Temporal.')
37+
svc.log.info('Configuration may have changed since. Please make sure they are in sync.')
38+
} else {
39+
throw new Error(err)
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)