-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathhelloworld.ts
More file actions
70 lines (62 loc) · 2.09 KB
/
helloworld.ts
File metadata and controls
70 lines (62 loc) · 2.09 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
/**
* Hello World — Minimal complete workflow lifecycle
*
* Demonstrates the bare minimum to:
* 1. Register a task definition
* 2. Register a workflow definition
* 3. Start a workflow
* 4. Poll and execute a task
* 5. Wait for completion and print the result
*
* Run:
* CONDUCTOR_SERVER_URL=http://localhost:8080 npx ts-node examples/helloworld.ts
*/
import {
OrkesClients,
ConductorWorkflow,
TaskHandler,
worker,
simpleTask,
} from "../src/sdk";
import type { Task } from "../src/open-api";
// ── Worker ──────────────────────────────────────────────────────────
const _helloTask = worker({ taskDefName: "hello_task", registerTaskDef: true })(
async (task: Task) => {
const name = (task.inputData?.name as string) ?? "World";
return {
status: "COMPLETED",
outputData: { message: `Hello, ${name}!` },
};
}
);
// ── Main ────────────────────────────────────────────────────────────
async function main() {
const clients = await OrkesClients.from();
const workflowClient = clients.getWorkflowClient();
const client = clients.getClient();
// Define & register workflow
const wf = new ConductorWorkflow(workflowClient, "hello_world")
.add(
simpleTask("hello_ref", "hello_task", {
name: "${workflow.input.name}",
})
)
.outputParameters({
message: "${hello_ref.output.message}",
});
await wf.register(true);
console.log("Workflow registered.");
// Start workers
const handler = new TaskHandler({ client, scanForDecorated: true });
await handler.startWorkers();
// Execute and wait for result
const run = await wf.execute({ name: "TypeScript" });
console.log("Status:", run.status);
console.log("Output:", JSON.stringify(run.output, null, 2));
await handler.stopWorkers();
process.exit(0);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});