-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathquickstart.ts
More file actions
75 lines (67 loc) · 2.37 KB
/
quickstart.ts
File metadata and controls
75 lines (67 loc) · 2.37 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
/**
* Quickstart — 60-second introduction to Conductor + TypeScript
*
* Demonstrates the minimal steps to define a worker, build a workflow,
* register it, execute it, and print the result.
*
* Run:
* CONDUCTOR_SERVER_URL=http://localhost:8080 npx ts-node examples/quickstart.ts
*
* Environment variables:
* CONDUCTOR_SERVER_URL — Conductor server URL (required)
* CONDUCTOR_AUTH_KEY — Auth key (optional, for Orkes Cloud)
* CONDUCTOR_AUTH_SECRET — Auth secret (optional, for Orkes Cloud)
*/
import {
OrkesClients,
ConductorWorkflow,
TaskHandler,
worker,
simpleTask,
} from "../src/sdk";
import type { Task } from "../src/open-api";
// ── 1. Define a worker ──────────────────────────────────────────────
const _greet = worker({ taskDefName: "greet", registerTaskDef: true })(
async (task: Task) => {
const name = (task.inputData?.name as string) ?? "World";
return {
status: "COMPLETED",
outputData: { greeting: `Hello, ${name}!` },
};
}
);
// ── 2. Main ─────────────────────────────────────────────────────────
async function main() {
// Connect to Conductor (reads CONDUCTOR_SERVER_URL / AUTH env vars)
const clients = await OrkesClients.from();
const workflowClient = clients.getWorkflowClient();
const client = clients.getClient();
// Build a simple workflow
const wf = new ConductorWorkflow(workflowClient, "quickstart_workflow")
.description("A minimal quickstart workflow")
.add(
simpleTask("greet_ref", "greet", {
name: "${workflow.input.name}",
})
)
.outputParameters({
greeting: "${greet_ref.output.greeting}",
});
// Register the workflow
await wf.register(true);
console.log("Registered workflow:", wf.getName());
// Start polling for tasks
const handler = new TaskHandler({ client, scanForDecorated: true });
await handler.startWorkers();
// Execute the workflow synchronously
const run = await wf.execute({ name: "Conductor" });
console.log("Workflow status:", run.status);
console.log("Output:", run.output);
// Cleanup
await handler.stopWorkers();
process.exit(0);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});