/
start-schedule.ts
64 lines (56 loc) · 1.57 KB
/
start-schedule.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Connection, Client, ScheduleOverlapPolicy } from '@temporalio/client';
import { reminder } from './workflows';
async function run() {
const client = new Client({
connection: await Connection.connect(),
});
// https://typescript.temporal.io/api/classes/client.ScheduleClient#create
const schedule = await client.schedule.create({
action: {
type: 'startWorkflow',
workflowType: reminder,
args: ['♻️ Dear future self, please take out the recycling tonight. Sincerely, past you ❤️'],
taskQueue: 'schedules',
},
scheduleId: 'sample-schedule',
policies: {
catchupWindow: '1 day',
overlap: ScheduleOverlapPolicy.ALLOW_ALL,
},
spec: {
intervals: [{ every: '10s' }],
// or periodic calendar times:
// calendars: [
// {
// comment: 'every wednesday at 8:30pm',
// dayOfWeek: 'WEDNESDAY',
// hour: 20,
// minute: 30,
// },
// ],
// or a single datetime:
// calendars: [
// {
// comment: '1/1/23 at 9am',
// year: 2023,
// month: 1,
// dayOfMonth: 1,
// hour: 9,
// },
// ],
},
});
console.log(`Started schedule '${schedule.scheduleId}'.
The reminder Workflow will run and log from the Worker every 10 seconds.
You can now run:
npm run schedule.go-faster
npm run schedule.pause
npm run schedule.unpause
npm run schedule.delete
`);
await client.connection.close();
}
run().catch((err) => {
console.error(err);
process.exit(1);
});