-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
40 lines (37 loc) · 919 Bytes
/
index.ts
File metadata and controls
40 lines (37 loc) · 919 Bytes
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 { task } from '@renderinc/sdk/workflows'
// A minimal task definition
const calculateSquare = task(
{ name: 'calculateSquare' },
function calculateSquare(a: number): number {
return a * a
}
)
// A task that chains two parallel runs
const sumSquares = task(
{ name: 'sumSquares' },
async function sumSquares(a: number, b: number): Promise<number> {
const [result1, result2] = await Promise.all([
calculateSquare(a),
calculateSquare(b)
])
return result1 + result2
}
)
// A task that flips a coin and retries on "tails"
// (Illustrates specifying retry logic on failure)
const flipCoin = task(
{
name: 'flipCoin',
retry: {
maxRetries: 3,
waitDurationMs: 1000,
backoffScaling: 1.5
}
},
function flipCoin(): string {
if (Math.random() < 0.5) {
throw new Error('Flipped tails! Retrying.')
}
return 'Flipped heads!'
}
)