Skip to content

Commit 25a9e57

Browse files
[developer] Auto-commit: Implement Core Feature
1 parent 067f20a commit 25a9e57

1 file changed

Lines changed: 28 additions & 14 deletions

File tree

src/integrations/ralph/monitoring/swarm-registry.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface RegisteredSwarm {
1818
export class SwarmRegistry extends EventEmitter {
1919
private static instance: SwarmRegistry | null = null;
2020
private swarms: Map<string, RegisteredSwarm> = new Map();
21-
21+
2222
private constructor() {
2323
super();
2424
logger.info('SwarmRegistry initialized');
@@ -36,18 +36,18 @@ export class SwarmRegistry extends EventEmitter {
3636
*/
3737
registerSwarm(coordinator: SwarmCoordinator, description: string): string {
3838
const swarmId = this.generateSwarmId();
39-
39+
4040
const registration: RegisteredSwarm = {
4141
id: swarmId,
4242
coordinator,
4343
startTime: Date.now(),
4444
status: 'active',
45-
description
45+
description,
4646
};
47-
47+
4848
this.swarms.set(swarmId, registration);
4949
this.emit('swarmRegistered', registration);
50-
50+
5151
logger.info(`Swarm registered: ${swarmId} - ${description}`);
5252
return swarmId;
5353
}
@@ -76,14 +76,17 @@ export class SwarmRegistry extends EventEmitter {
7676
*/
7777
listActiveSwarms(): RegisteredSwarm[] {
7878
return Array.from(this.swarms.values()).filter(
79-
swarm => swarm.status === 'active'
79+
(swarm) => swarm.status === 'active'
8080
);
8181
}
8282

8383
/**
8484
* Update swarm status
8585
*/
86-
updateSwarmStatus(swarmId: string, status: 'active' | 'idle' | 'completed' | 'error'): void {
86+
updateSwarmStatus(
87+
swarmId: string,
88+
status: 'active' | 'idle' | 'completed' | 'error'
89+
): void {
8790
const swarm = this.swarms.get(swarmId);
8891
if (swarm) {
8992
swarm.status = status;
@@ -102,23 +105,34 @@ export class SwarmRegistry extends EventEmitter {
102105
averageUptime: number;
103106
} {
104107
const active = this.listActiveSwarms();
105-
const completed = Array.from(this.swarms.values()).filter(s => s.status === 'completed');
106-
107-
const totalUptime = active.reduce((sum, swarm) =>
108-
sum + (Date.now() - swarm.startTime), 0
108+
const completed = Array.from(this.swarms.values()).filter(
109+
(s) => s.status === 'completed'
110+
);
111+
112+
const totalUptime = active.reduce(
113+
(sum, swarm) => sum + (Date.now() - swarm.startTime),
114+
0
109115
);
110-
116+
111117
return {
112118
totalSwarms: this.swarms.size,
113119
activeSwarms: active.length,
114120
completedSwarms: completed.length,
115-
averageUptime: active.length > 0 ? totalUptime / active.length : 0
121+
averageUptime: active.length > 0 ? totalUptime / active.length : 0,
116122
};
117123
}
118124

125+
/**
126+
* Cleanup all swarms and reset registry
127+
*/
128+
cleanup(): void {
129+
this.swarms.clear();
130+
logger.info('SwarmRegistry cleaned up');
131+
}
132+
119133
private generateSwarmId(): string {
120134
return `swarm_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
121135
}
122136
}
123137

124-
export default SwarmRegistry;
138+
export default SwarmRegistry;

0 commit comments

Comments
 (0)