forked from temporalio/samples-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflows.ts
More file actions
40 lines (32 loc) · 1.1 KB
/
Copy pathworkflows.ts
File metadata and controls
40 lines (32 loc) · 1.1 KB
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
import { proxyActivities, sleep } from '@temporalio/workflow';
// Only import the activity types
import type { createActivities } from './activities';
export * from './updatable-timer';
export interface ProcessOrderOptions {
orderProcessingMS: number;
sendDelayedEmailTimeoutMS: number;
}
const { sendNotificationEmail } = proxyActivities<ReturnType<typeof createActivities>>({
startToCloseTimeout: '5m',
});
// @@@SNIPSTART typescript-timer-reminder-workflow
export async function processOrderWorkflow({
orderProcessingMS,
sendDelayedEmailTimeoutMS,
}: ProcessOrderOptions): Promise<string> {
let processing = true;
// Dynamically define the timeout based on given input
const { processOrder } = proxyActivities<ReturnType<typeof createActivities>>({
startToCloseTimeout: orderProcessingMS,
});
const processOrderPromise = processOrder().then(() => {
processing = false;
});
await Promise.race([processOrderPromise, sleep(sendDelayedEmailTimeoutMS)]);
if (processing) {
await sendNotificationEmail();
await processOrderPromise;
}
return 'Order completed!';
}
// @@@SNIPEND