@aikirun/worker 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +19 -110
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # @aikirun/worker
2
2
 
3
- Worker SDK for Aiki durable execution platform - execute workflows and tasks with durable state management and automatic
4
- recovery.
3
+ Worker SDK for Aiki durable execution platform.
5
4
 
6
5
  ## Installation
7
6
 
@@ -11,138 +10,48 @@ npm install @aikirun/worker
11
10
 
12
11
  ## Quick Start
13
12
 
14
- ### Create and Spawn a Worker
15
-
16
13
  ```typescript
17
14
  import { worker } from "@aikirun/worker";
18
15
  import { client } from "@aikirun/client";
19
- import { onboardingWorkflowV1 } from "./workflows.ts";
20
-
21
- // Define worker
22
- const aikiWorker = worker({
23
- name: "worker-1",
24
- workflows: [onboardingWorkflowV1],
25
- subscriber: { type: "redis" },
26
- opts: {
27
- maxConcurrentWorkflowRuns: 10,
28
- },
29
- });
16
+ import { orderWorkflowV1 } from "./workflows.ts";
30
17
 
31
- // Initialize client
32
18
  const aikiClient = await client({
33
19
  url: "http://localhost:9876",
34
20
  redis: { host: "localhost", port: 6379 },
35
21
  });
36
22
 
37
- // Spawn worker
38
- const handle = await aikiWorker.spawn(aiki);
39
- ```
40
-
41
- ### Graceful Shutdown
23
+ const aikiWorker = worker({
24
+ name: "order-worker",
25
+ workflows: [orderWorkflowV1],
26
+ });
42
27
 
43
- ```typescript
44
- import process from "node:process";
28
+ const handle = await aikiWorker.spawn(aikiClient);
45
29
 
46
- const shutdown = async () => {
30
+ // Graceful shutdown
31
+ process.on("SIGTERM", async () => {
47
32
  await handle.stop();
48
- await aiki.close();
33
+ await aikiClient.close();
49
34
  process.exit(0);
50
- };
51
-
52
- process.on("SIGINT", shutdown);
53
- process.on("SIGTERM", shutdown);
54
- ```
55
-
56
- ## Features
57
-
58
- - **Durable Execution** - Automatically resume from failures without losing progress
59
- - **Horizontal Scaling** - Multiple workers process workflows in parallel
60
- - **State Management** - Persist execution state at each step
61
- - **Automatic Recovery** - Detect stuck workflows and retry automatically
62
- - **Polling Strategies** - Adaptive polling with configurable backoff
63
- - **Graceful Shutdown** - Clean worker termination with in-flight workflow handling
64
-
65
- ## Horizontal Scaling
66
-
67
- Scale workers by creating separate definitions to isolate workflows or shard by key:
68
-
69
- ```typescript
70
- // Separate workers by workflow type
71
- const orderWorker = worker({ name: "orders", workflows: [orderWorkflowV1] });
72
- const emailWorker = worker({ name: "emails", workflows: [emailWorkflowV1] });
73
-
74
- await orderWorker.spawn(client);
75
- await emailWorker.spawn(client);
76
- ```
77
-
78
- ```typescript
79
- // Shard workers by key (reuse base definition with different shards)
80
- const orderWorker = worker({ name: "order-processor", workflows: [orderWorkflowV1] });
81
-
82
- await orderWorker.with().opt("shards", ["us-east", "us-west"]).spawn(client);
83
- await orderWorker.with().opt("shards", ["eu-west"]).spawn(client);
84
- ```
85
-
86
- ## Worker Configuration
87
-
88
- ### Params (required for worker identity)
89
-
90
- ```typescript
91
- interface WorkerParams {
92
- name: string; // Unique worker name
93
- workflows: WorkflowVersion[]; // Workflow versions to execute
94
- subscriber?: SubscriberStrategy; // Message subscriber (default: redis)
95
- }
96
- ```
97
-
98
- ### Options (via `opts` param or `with()` builder)
99
-
100
- ```typescript
101
- interface WorkerOptions {
102
- maxConcurrentWorkflowRuns?: number; // Concurrency limit (default: 1)
103
- workflowRun?: {
104
- heartbeatIntervalMs?: number; // Heartbeat interval (default: 30s)
105
- };
106
- gracefulShutdownTimeoutMs?: number; // Shutdown timeout (default: 5s)
107
- shards?: string[]; // Optional shards for distributed work
108
- }
109
- ```
110
-
111
- ## Workflow Registration
112
-
113
- Workers receive workflow versions through the `workflows` param:
114
-
115
- ```typescript
116
- const aikiWorker = worker({
117
- name: "worker-1",
118
- workflows: [workflowV1, workflowV2, anotherWorkflowV1],
119
- subscriber: { type: "redis" },
120
35
  });
121
36
  ```
122
37
 
123
- The worker automatically discovers and executes the registered workflow versions.
124
-
125
- ## State Persistence
38
+ ## Features
126
39
 
127
- Workers store execution state at each step:
40
+ - **Horizontal Scaling** - Run multiple workers to share workload
41
+ - **Automatic Recovery** - Resume from failures without losing progress
42
+ - **Heartbeat Monitoring** - Detect and recover stuck workflows
43
+ - **Graceful Shutdown** - Complete active work before stopping
44
+ - **Sharding** - Route workflows to specific workers
128
45
 
129
- - Task completion status
130
- - Sleep/wait checkpoints
131
- - Event acknowledgments
132
- - Child workflow results
46
+ ## Documentation
133
47
 
134
- This allows workflows to resume from the exact point of failure.
48
+ For comprehensive documentation including scaling strategies, configuration options, and how workers operate, see the [Workers Guide](https://aiki.run/docs/core-concepts/workers).
135
49
 
136
50
  ## Related Packages
137
51
 
138
- - [@aikirun/client](https://www.npmjs.com/package/@aikirun/client) - Start workflows
52
+ - [@aikirun/client](https://www.npmjs.com/package/@aikirun/client) - Connect to Aiki server
139
53
  - [@aikirun/workflow](https://www.npmjs.com/package/@aikirun/workflow) - Define workflows
140
54
  - [@aikirun/task](https://www.npmjs.com/package/@aikirun/task) - Define tasks
141
- - [@aikirun/types](https://www.npmjs.com/package/@aikirun/types) - Type definitions
142
-
143
- ## Changelog
144
-
145
- See the [CHANGELOG](https://github.com/aikirun/aiki/blob/main/CHANGELOG.md) for version history.
146
55
 
147
56
  ## License
148
57
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aikirun/worker",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "Worker SDK for Aiki - execute workflows and tasks with durable state management and automatic recovery",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,9 +18,9 @@
18
18
  "build": "tsup"
19
19
  },
20
20
  "dependencies": {
21
- "@aikirun/types": "0.9.0",
22
- "@aikirun/client": "0.9.0",
23
- "@aikirun/workflow": "0.9.0"
21
+ "@aikirun/types": "0.9.1",
22
+ "@aikirun/client": "0.9.1",
23
+ "@aikirun/workflow": "0.9.1"
24
24
  },
25
25
  "publishConfig": {
26
26
  "access": "public"