-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtask-configure.ts
More file actions
145 lines (133 loc) · 4.92 KB
/
task-configure.ts
File metadata and controls
145 lines (133 loc) · 4.92 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* Task Configure — Programmatic task definition management
*
* Demonstrates registering task definitions with MetadataClient:
* - Retry policies (FIXED, EXPONENTIAL_BACKOFF, LINEAR_BACKOFF)
* - Timeout configuration
* - Rate limiting
* - Concurrency limits
*
* Run:
* CONDUCTOR_SERVER_URL=http://localhost:8080 npx ts-node examples/task-configure.ts
*/
import { OrkesClients } from "../src/sdk";
async function main() {
const clients = await OrkesClients.from();
const metadataClient = clients.getMetadataClient();
// ── 1. Simple task definition ─────────────────────────────────────
await metadataClient.registerTask({
name: "cfg_simple_task",
description: "A simple task with defaults",
retryCount: 3,
retryLogic: "FIXED",
retryDelaySeconds: 10,
timeoutSeconds: 60,
responseTimeoutSeconds: 30,
});
console.log("1. Registered simple task definition: cfg_simple_task");
// ── 2. Task with exponential backoff ──────────────────────────────
await metadataClient.registerTask({
name: "cfg_backoff_task",
description: "Task with exponential backoff retry",
retryCount: 5,
retryLogic: "EXPONENTIAL_BACKOFF",
retryDelaySeconds: 5,
timeoutSeconds: 300,
responseTimeoutSeconds: 120,
});
console.log("2. Registered backoff task: cfg_backoff_task");
// ── 3. Task with rate limiting ────────────────────────────────────
await metadataClient.registerTask({
name: "cfg_rate_limited_task",
description: "Task with rate limiting",
retryCount: 3,
retryLogic: "FIXED",
retryDelaySeconds: 10,
timeoutSeconds: 120,
responseTimeoutSeconds: 60,
rateLimitPerFrequency: 10,
rateLimitFrequencyInSeconds: 60,
});
console.log("3. Registered rate-limited task: cfg_rate_limited_task");
// ── 4. Task with concurrency limit ────────────────────────────────
await metadataClient.registerTask({
name: "cfg_concurrent_task",
description: "Task with concurrency execution limit",
retryCount: 2,
retryLogic: "FIXED",
retryDelaySeconds: 5,
timeoutSeconds: 180,
responseTimeoutSeconds: 60,
concurrentExecLimit: 5,
});
console.log("4. Registered concurrent-limited task: cfg_concurrent_task");
// ── 5. Long-running task with callback ────────────────────────────
await metadataClient.registerTask({
name: "cfg_long_running_task",
description: "Long-running task that uses callbacks",
retryCount: 1,
retryLogic: "FIXED",
retryDelaySeconds: 30,
timeoutSeconds: 3600,
responseTimeoutSeconds: 600,
pollTimeoutSeconds: 60,
});
console.log("5. Registered long-running task: cfg_long_running_task");
// ── 6. Batch register multiple tasks ──────────────────────────────
await metadataClient.registerTasks([
{
name: "cfg_batch_task_1",
description: "Batch task 1",
retryCount: 3,
timeoutSeconds: 60,
responseTimeoutSeconds: 30,
},
{
name: "cfg_batch_task_2",
description: "Batch task 2",
retryCount: 3,
timeoutSeconds: 60,
responseTimeoutSeconds: 30,
},
{
name: "cfg_batch_task_3",
description: "Batch task 3",
retryCount: 3,
timeoutSeconds: 60,
responseTimeoutSeconds: 30,
},
]);
console.log("6. Batch registered 3 tasks");
// ── 7. Retrieve and display a task definition ─────────────────────
const taskDef = await metadataClient.getTask("cfg_backoff_task");
console.log("\n7. Retrieved task definition:");
console.log(JSON.stringify(taskDef, null, 2));
// ── 8. Update a task definition ───────────────────────────────────
await metadataClient.updateTask({
...taskDef,
retryCount: 10,
description: "Updated: more retries",
});
console.log("\n8. Updated cfg_backoff_task retryCount to 10");
// ── 9. Clean up ───────────────────────────────────────────────────
const tasksToClean = [
"cfg_simple_task",
"cfg_backoff_task",
"cfg_rate_limited_task",
"cfg_concurrent_task",
"cfg_long_running_task",
"cfg_batch_task_1",
"cfg_batch_task_2",
"cfg_batch_task_3",
];
for (const name of tasksToClean) {
await metadataClient.unregisterTask(name);
}
console.log("9. Cleaned up all task definitions");
console.log("\nDone.");
process.exit(0);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});