Skip to content

Commit 47323d4

Browse files
committed
multipool: add public client registry API and client event forwarding; add demos & update tests
- expose safe Client Registry API on MultiWorkflowPool (getClients, getClient, getClientsForWorkflow, getIdleClients, hasClientsForWorkflow, getPoolStats) - forward all ComfyUI WebSocket events through PoolEventManager as "client:<event>" with ClientEventPayload - add ClientEventPayload type and update interfaces/d.ts/maps - add demos/tests: event-forwarding-demo, client-registry-api-demo (src + dist + maps) - update profiling and two-stage simulation tests to use localhost hosts - update CHANGELOG to document new API, events, demos and added types
1 parent 49527a0 commit 47323d4

25 files changed

Lines changed: 890 additions & 19 deletions

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,24 @@ console.log('Profile Stats:', result.profileStats);
5656
* **JobQueueProcessor** – Per-workflow queue processing with event-driven job assignment
5757
* **JobStateRegistry** – Centralized job lifecycle management with profiling integration
5858
* **PoolEventManager** – Extensible event system for custom monitoring and integration
59+
* **Public Client Registry API** – Safe access to client information and pool statistics
60+
* `getClients()` – Get all registered clients with their current state
61+
* `getClient(url)` – Get specific client information by URL
62+
* `getClientsForWorkflow(workflow)` – Find clients with affinity for a workflow
63+
* `getIdleClients()` – Get all currently available workers
64+
* `hasClientsForWorkflow(workflow)` – Check if workflow can be executed
65+
* `getPoolStats()` – Comprehensive pool statistics (client counts, queue depths)
5966

6067
**Events Supported:**
6168

6269
* Job lifecycle: `job:queued`, `job:started`, `job:completed`, `job:failed`, `job:cancelled`
6370
* Progress tracking: Real-time progress updates with node execution tracking
6471
* Preview streaming: `b_preview_meta` events with blob and metadata
6572
* Client state: Automatic idle/busy transitions, offline detection
73+
* **All ComfyUI Events**: Every WebSocket event from clients is forwarded with `client:` prefix
74+
* Examples: `client:status`, `client:progress`, `client:executing`, `client:execution_cached`, `client:executed`, `client:execution_success`
75+
* Use `pool.attachEventHook(eventType, listener)` to subscribe to any client event
76+
* Event payload includes `clientUrl`, `clientName`, `eventType`, and original `eventData`
6677

6778
**Performance:**
6879

@@ -75,14 +86,16 @@ console.log('Profile Stats:', result.profileStats);
7586

7687
* `docs/multipool-profiling.md` – Profiling guide for MultiWorkflowPool
7788
* `src/multipool/tests/profiling-demo.ts` – Complete profiling demonstration
89+
* `src/multipool/tests/event-forwarding-demo.ts` – Event system demonstration
90+
* `src/multipool/tests/client-registry-api-demo.ts` – Client registry API examples
7891
* `src/multipool/tests/two-stage-edit-simulation.ts` – Multi-user workflow simulation
7992

8093
**New Exports:**
8194

8295
* `MultiWorkflowPool` – Main pool class
8396
* `JobProfiler` – Per-job execution profiling (MultiWorkflowPool variant)
8497
* `Logger` / `createLogger` – Structured logging infrastructure
85-
* Types: `MultiWorkflowPoolOptions`, `JobResults`, `JobState`, `JobProfileStats`
98+
* Types: `MultiWorkflowPoolOptions`, `JobResults`, `JobState`, `JobProfileStats`, `PoolEvent`, `ClientEventPayload`
8699

87100
**Use Cases:**
88101

dist/multipool/interfaces.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
import { LogLevel } from "./logger.js";
2+
/**
3+
* Pool event emitted through PoolEventManager
4+
* All ComfyUI client events are forwarded with the prefix "client:"
5+
*/
26
export interface PoolEvent {
37
type: string;
48
payload: any;
59
}
10+
/**
11+
* Client event payload forwarded from ComfyUI WebSocket events
12+
*/
13+
export interface ClientEventPayload {
14+
/** URL of the client that emitted the event */
15+
clientUrl: string;
16+
/** Node name of the client */
17+
clientName: string;
18+
/** Original ComfyUI event type (status, progress, executing, etc.) */
19+
eventType: string;
20+
/** Original event data from ComfyUI */
21+
eventData: any;
22+
}
623
export interface MultiWorkflowPoolOptions {
724
connectionTimeoutMs?: number;
825
enableMonitoring?: boolean;

dist/multipool/interfaces.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/multipool/multi-workflow-pool.d.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,65 @@ export declare class MultiWorkflowPool {
3939
blob: Blob;
4040
metadata: any;
4141
}) => void): void;
42+
/**
43+
* Get a list of all registered clients with their current state
44+
* @returns Array of client information objects
45+
*/
46+
getClients(): Array<{
47+
url: string;
48+
nodeName: string;
49+
state: "idle" | "busy" | "offline";
50+
priority?: number;
51+
workflowAffinityHashes?: string[];
52+
}>;
53+
/**
54+
* Get information about a specific client by URL
55+
* @param clientUrl - The URL of the client to query
56+
* @returns Client information or null if not found
57+
*/
58+
getClient(clientUrl: string): {
59+
url: string;
60+
nodeName: string;
61+
state: "idle" | "busy" | "offline";
62+
priority?: number;
63+
workflowAffinityHashes?: string[];
64+
} | null;
65+
/**
66+
* Get all clients that have affinity for a specific workflow
67+
* @param workflow - The workflow to check affinity for
68+
* @returns Array of client URLs that can handle this workflow
69+
*/
70+
getClientsForWorkflow(workflow: Workflow<any>): string[];
71+
/**
72+
* Get all idle clients currently available for work
73+
* @returns Array of idle client information
74+
*/
75+
getIdleClients(): Array<{
76+
url: string;
77+
nodeName: string;
78+
priority?: number;
79+
}>;
80+
/**
81+
* Check if there are any clients available for a specific workflow
82+
* @param workflow - The workflow to check
83+
* @returns True if at least one client has affinity for this workflow
84+
*/
85+
hasClientsForWorkflow(workflow: Workflow<any>): boolean;
86+
/**
87+
* Get statistics about the pool's current state
88+
* @returns Pool statistics including client counts and queue depths
89+
*/
90+
getPoolStats(): {
91+
totalClients: number;
92+
idleClients: number;
93+
busyClients: number;
94+
offlineClients: number;
95+
totalQueues: number;
96+
queues: Array<{
97+
workflowHash: string;
98+
pendingJobs: number;
99+
type: "general" | "specific";
100+
}>;
101+
};
42102
}
43103
//# sourceMappingURL=multi-workflow-pool.d.ts.map

dist/multipool/multi-workflow-pool.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/multipool/multi-workflow-pool.js

Lines changed: 114 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)