@aikirun/worker 0.23.0 → 0.24.0

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.
package/README.md CHANGED
@@ -15,14 +15,12 @@ import { worker } from "@aikirun/worker";
15
15
  import { client } from "@aikirun/client";
16
16
  import { orderWorkflowV1 } from "./workflows.ts";
17
17
 
18
- // Set AIKI_API_KEY env variable or pass apiKey option
19
18
  const aikiClient = client({
20
19
  url: "http://localhost:9850",
21
- redis: { host: "localhost", port: 6379 },
20
+ apiKey: "your-api-key",
22
21
  });
23
22
 
24
23
  const aikiWorker = worker({
25
- name: "order-worker",
26
24
  workflows: [orderWorkflowV1],
27
25
  });
28
26
 
@@ -31,7 +29,6 @@ const handle = await aikiWorker.spawn(aikiClient);
31
29
  // Graceful shutdown
32
30
  process.on("SIGTERM", async () => {
33
31
  await handle.stop();
34
- await aikiClient.close();
35
32
  process.exit(0);
36
33
  });
37
34
  ```
@@ -43,6 +40,7 @@ process.on("SIGTERM", async () => {
43
40
  - **Heartbeat Monitoring** - Detect and recover stuck workflows
44
41
  - **Graceful Shutdown** - Complete active work before stopping
45
42
  - **Sharding** - Route workflows to specific workers
43
+ - **Pluggable Subscribers** - Swap work discovery transport (DB polling default, Redis Streams via `@aikirun/subscriber-redis`, or bring your own)
46
44
 
47
45
  ## Documentation
48
46
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { Client, SubscriberStrategy } from '@aikirun/client';
2
- import { WorkerName, WorkerId } from '@aikirun/types/worker';
3
- import { WorkflowVersion } from '@aikirun/workflow';
1
+ import { Client } from '@aikirun/types/client';
2
+ import { CreateSubscriber } from '@aikirun/types/subscriber';
3
+ import { WorkerId } from '@aikirun/types/worker';
4
+ import { WorkflowExecutionOptions, AnyWorkflowVersion } from '@aikirun/workflow';
4
5
 
5
6
  type NonEmptyArray<T> = [T, ...T[]];
6
7
 
@@ -25,17 +26,15 @@ type TypeOfValueAtPath<T extends object, Path extends PathFromObject<T>> = Path
25
26
  * execution, which returns a handle for controlling the running worker.
26
27
  *
27
28
  * @param params - Worker configuration parameters
28
- * @param params.name - Unique worker name for identification and monitoring
29
29
  * @param params.workflows - Array of workflow versions this worker can execute
30
- * @param params.subscriber - Message subscriber strategy (default: redis)
30
+ * @param params.subscriber - Optional subscriber factory for work discovery (default: DB polling)
31
31
  * @returns Worker definition, call spawn(client) to begin execution
32
32
  *
33
33
  * @example
34
34
  * ```typescript
35
35
  * export const myWorker = worker({
36
- * name: "order-worker",
37
36
  * workflows: [orderWorkflowV1, paymentWorkflowV1],
38
- * opts: {
37
+ * options: {
39
38
  * maxConcurrentWorkflowRuns: 10,
40
39
  * },
41
40
  * });
@@ -44,20 +43,18 @@ type TypeOfValueAtPath<T extends object, Path extends PathFromObject<T>> = Path
44
43
  *
45
44
  * process.on("SIGINT", async () => {
46
45
  * await handle.stop();
47
- * await client.close();
48
46
  * });
49
47
  * ```
50
48
  */
51
49
  declare function worker(params: WorkerParams): Worker;
52
50
  interface WorkerParams {
53
- name: string;
54
- workflows: WorkflowVersion<any, any, any, any>[];
55
- subscriber?: SubscriberStrategy;
56
- opts?: WorkerDefinitionOptions;
51
+ workflows: AnyWorkflowVersion[];
52
+ subscriber?: CreateSubscriber;
53
+ options?: WorkerDefinitionOptions;
57
54
  }
58
55
  interface WorkerDefinitionOptions {
59
56
  maxConcurrentWorkflowRuns?: number;
60
- workflowRun?: WorkflowRunOptions;
57
+ workflowRun?: WorkflowExecutionOptions;
61
58
  gracefulShutdownTimeoutMs?: number;
62
59
  }
63
60
  interface WorkerSpawnOptions extends WorkerDefinitionOptions {
@@ -75,26 +72,12 @@ interface WorkerSpawnOptions extends WorkerDefinitionOptions {
75
72
  id: string;
76
73
  };
77
74
  }
78
- interface WorkflowRunOptions {
79
- heartbeatIntervalMs?: number;
80
- /**
81
- * Threshold for spinning vs persisting delays (default: 10ms).
82
- *
83
- * Delays <= threshold: In-memory wait (fast, no history, not durable)
84
- * Delays > threshold: Server state transition (history recorded, durable)
85
- *
86
- * Set to 0 to record all delays in transition history.
87
- */
88
- spinThresholdMs?: number;
89
- }
90
75
  interface Worker {
91
- name: WorkerName;
92
76
  with(): WorkerBuilder;
93
77
  spawn: <AppContext>(client: Client<AppContext>) => Promise<WorkerHandle>;
94
78
  }
95
79
  interface WorkerHandle {
96
80
  id: WorkerId;
97
- name: WorkerName;
98
81
  stop: () => Promise<void>;
99
82
  }
100
83
  interface WorkerBuilder {