snow-flow 8.39.0 → 8.39.2
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 +9 -9
- package/dist/cli/enterprise.js +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +41 -37
- package/dist/cli.js.map +1 -1
- package/dist/mcp/base-mcp-server.d.ts +3 -0
- package/dist/mcp/base-mcp-server.d.ts.map +1 -1
- package/dist/mcp/base-mcp-server.js +48 -21
- package/dist/mcp/base-mcp-server.js.map +1 -1
- package/dist/mcp/servicenow-deployment-mcp.js +1 -1
- package/dist/mcp/snow-flow-mcp.js +48 -31
- package/dist/mcp/snow-flow-mcp.js.map +1 -1
- package/dist/monitoring/performance-tracker.d.ts +1 -1
- package/dist/monitoring/performance-tracker.d.ts.map +1 -1
- package/dist/monitoring/performance-tracker.js +44 -9
- package/dist/monitoring/performance-tracker.js.map +1 -1
- package/dist/snow-flow-system.d.ts +14 -3
- package/dist/snow-flow-system.d.ts.map +1 -1
- package/dist/snow-flow-system.js +66 -22
- package/dist/snow-flow-system.js.map +1 -1
- package/dist/templates/readme-template.d.ts +1 -1
- package/dist/templates/readme-template.js +13 -13
- package/dist/types/snow-flow.types.d.ts +1 -0
- package/dist/types/snow-flow.types.d.ts.map +1 -1
- package/dist/utils/mcp-on-demand-manager.d.ts.map +1 -1
- package/dist/utils/mcp-on-demand-manager.js +18 -5
- package/dist/utils/mcp-on-demand-manager.js.map +1 -1
- package/dist/utils/mcp-persistent-guard.d.ts +4 -0
- package/dist/utils/mcp-persistent-guard.d.ts.map +1 -1
- package/dist/utils/mcp-persistent-guard.js +26 -2
- package/dist/utils/mcp-persistent-guard.js.map +1 -1
- package/dist/utils/mcp-process-manager.d.ts.map +1 -1
- package/dist/utils/mcp-process-manager.js +5 -0
- package/dist/utils/mcp-process-manager.js.map +1 -1
- package/dist/utils/memory-safe-collections.d.ts +119 -0
- package/dist/utils/memory-safe-collections.d.ts.map +1 -0
- package/dist/utils/memory-safe-collections.js +212 -0
- package/dist/utils/memory-safe-collections.js.map +1 -0
- package/dist/utils/timer-registry.d.ts +138 -0
- package/dist/utils/timer-registry.d.ts.map +1 -0
- package/dist/utils/timer-registry.js +289 -0
- package/dist/utils/timer-registry.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timer Registry - Centralized timer management for snow-flow
|
|
3
|
+
* Ensures all intervals/timeouts are properly tracked and cleaned up
|
|
4
|
+
*
|
|
5
|
+
* This module provides automatic cleanup ONLY during graceful shutdown.
|
|
6
|
+
* Timers are NOT cleaned up aggressively during normal operation.
|
|
7
|
+
*
|
|
8
|
+
* @module timer-registry
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Shutdown handler function type
|
|
12
|
+
*/
|
|
13
|
+
type ShutdownHandler = () => Promise<void> | void;
|
|
14
|
+
/**
|
|
15
|
+
* TimerRegistry - Singleton class for centralized timer management
|
|
16
|
+
*
|
|
17
|
+
* Features:
|
|
18
|
+
* - Automatic cleanup on process exit
|
|
19
|
+
* - Named timers for easy management
|
|
20
|
+
* - Shutdown handlers for graceful cleanup
|
|
21
|
+
* - Statistics and monitoring
|
|
22
|
+
*/
|
|
23
|
+
export declare class TimerRegistry {
|
|
24
|
+
private static instance;
|
|
25
|
+
private intervals;
|
|
26
|
+
private timeouts;
|
|
27
|
+
private shutdownHandlers;
|
|
28
|
+
private logger;
|
|
29
|
+
private isShuttingDown;
|
|
30
|
+
private shutdownHandlersRegistered;
|
|
31
|
+
private constructor();
|
|
32
|
+
/**
|
|
33
|
+
* Get the singleton instance
|
|
34
|
+
*/
|
|
35
|
+
static getInstance(): TimerRegistry;
|
|
36
|
+
/**
|
|
37
|
+
* Register global shutdown handlers (only once)
|
|
38
|
+
*/
|
|
39
|
+
private registerGlobalShutdownHandlers;
|
|
40
|
+
/**
|
|
41
|
+
* Register a named interval
|
|
42
|
+
*
|
|
43
|
+
* @param id Unique identifier for the interval
|
|
44
|
+
* @param callback Function to execute
|
|
45
|
+
* @param ms Interval in milliseconds
|
|
46
|
+
* @param unref If true, don't keep the process alive for this timer (default: true)
|
|
47
|
+
* @returns The NodeJS.Timeout object
|
|
48
|
+
*/
|
|
49
|
+
registerInterval(id: string, callback: () => void | Promise<void>, ms: number, unref?: boolean): NodeJS.Timeout;
|
|
50
|
+
/**
|
|
51
|
+
* Register a named timeout
|
|
52
|
+
*
|
|
53
|
+
* @param id Unique identifier for the timeout
|
|
54
|
+
* @param callback Function to execute
|
|
55
|
+
* @param ms Delay in milliseconds
|
|
56
|
+
* @returns The NodeJS.Timeout object
|
|
57
|
+
*/
|
|
58
|
+
registerTimeout(id: string, callback: () => void | Promise<void>, ms: number): NodeJS.Timeout;
|
|
59
|
+
/**
|
|
60
|
+
* Clear a named interval
|
|
61
|
+
* @param id The interval identifier
|
|
62
|
+
*/
|
|
63
|
+
clearInterval(id: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* Clear a named timeout
|
|
66
|
+
* @param id The timeout identifier
|
|
67
|
+
*/
|
|
68
|
+
clearTimeout(id: string): void;
|
|
69
|
+
/**
|
|
70
|
+
* Check if an interval exists
|
|
71
|
+
* @param id The interval identifier
|
|
72
|
+
*/
|
|
73
|
+
hasInterval(id: string): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Check if a timeout exists
|
|
76
|
+
* @param id The timeout identifier
|
|
77
|
+
*/
|
|
78
|
+
hasTimeout(id: string): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Register a shutdown handler
|
|
81
|
+
* Called during cleanup() in reverse order of registration
|
|
82
|
+
*
|
|
83
|
+
* @param handler Async function to call during shutdown
|
|
84
|
+
*/
|
|
85
|
+
registerShutdownHandler(handler: ShutdownHandler): void;
|
|
86
|
+
/**
|
|
87
|
+
* Remove a shutdown handler
|
|
88
|
+
* @param handler The handler to remove
|
|
89
|
+
*/
|
|
90
|
+
removeShutdownHandler(handler: ShutdownHandler): void;
|
|
91
|
+
/**
|
|
92
|
+
* Cleanup all timers and run shutdown handlers
|
|
93
|
+
*/
|
|
94
|
+
cleanup(): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Get statistics about registered timers
|
|
97
|
+
*/
|
|
98
|
+
getStats(): {
|
|
99
|
+
intervals: number;
|
|
100
|
+
timeouts: number;
|
|
101
|
+
shutdownHandlers: number;
|
|
102
|
+
intervalIds: string[];
|
|
103
|
+
timeoutIds: string[];
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Get detailed information about all timers
|
|
107
|
+
*/
|
|
108
|
+
getDetailedStats(): {
|
|
109
|
+
intervals: Array<{
|
|
110
|
+
id: string;
|
|
111
|
+
ageMs: number;
|
|
112
|
+
callback: string;
|
|
113
|
+
}>;
|
|
114
|
+
timeouts: Array<{
|
|
115
|
+
id: string;
|
|
116
|
+
ageMs: number;
|
|
117
|
+
callback: string;
|
|
118
|
+
}>;
|
|
119
|
+
shutdownHandlerCount: number;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Clear all timers by prefix
|
|
123
|
+
* Useful for cleaning up all timers from a specific component
|
|
124
|
+
*
|
|
125
|
+
* @param prefix The prefix to match (e.g., 'mcp-' clears 'mcp-auth', 'mcp-metrics', etc.)
|
|
126
|
+
*/
|
|
127
|
+
clearByPrefix(prefix: string): {
|
|
128
|
+
intervals: number;
|
|
129
|
+
timeouts: number;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Singleton instance of TimerRegistry
|
|
134
|
+
* Use this for all timer management in snow-flow
|
|
135
|
+
*/
|
|
136
|
+
export declare const timerRegistry: TimerRegistry;
|
|
137
|
+
export {};
|
|
138
|
+
//# sourceMappingURL=timer-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer-registry.d.ts","sourceRoot":"","sources":["../../src/utils/timer-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG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,IAAI,CAAC;IAiC9B;;OAEG;IACH,QAAQ,IAAI;QACV,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,gBAAgB,EAAE,MAAM,CAAC;QACzB,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,UAAU,EAAE,MAAM,EAAE,CAAC;KACtB;IAUD;;OAEG;IACH,gBAAgB,IAAI;QAClB,SAAS,EAAE,KAAK,CAAC;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAClE,QAAQ,EAAE,KAAK,CAAC;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QACjE,oBAAoB,EAAE,MAAM,CAAC;KAC9B;IAkBD;;;;;OAKG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE;CAmCvE;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,eAA8B,CAAC"}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Timer Registry - Centralized timer management for snow-flow
|
|
4
|
+
* Ensures all intervals/timeouts are properly tracked and cleaned up
|
|
5
|
+
*
|
|
6
|
+
* This module provides automatic cleanup ONLY during graceful shutdown.
|
|
7
|
+
* Timers are NOT cleaned up aggressively during normal operation.
|
|
8
|
+
*
|
|
9
|
+
* @module timer-registry
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.timerRegistry = exports.TimerRegistry = void 0;
|
|
13
|
+
const logger_js_1 = require("./logger.js");
|
|
14
|
+
/**
|
|
15
|
+
* TimerRegistry - Singleton class for centralized timer management
|
|
16
|
+
*
|
|
17
|
+
* Features:
|
|
18
|
+
* - Automatic cleanup on process exit
|
|
19
|
+
* - Named timers for easy management
|
|
20
|
+
* - Shutdown handlers for graceful cleanup
|
|
21
|
+
* - Statistics and monitoring
|
|
22
|
+
*/
|
|
23
|
+
class TimerRegistry {
|
|
24
|
+
constructor() {
|
|
25
|
+
this.intervals = new Map();
|
|
26
|
+
this.timeouts = new Map();
|
|
27
|
+
this.shutdownHandlers = [];
|
|
28
|
+
this.isShuttingDown = false;
|
|
29
|
+
this.shutdownHandlersRegistered = false;
|
|
30
|
+
this.logger = new logger_js_1.Logger('TimerRegistry');
|
|
31
|
+
this.registerGlobalShutdownHandlers();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get the singleton instance
|
|
35
|
+
*/
|
|
36
|
+
static getInstance() {
|
|
37
|
+
if (!TimerRegistry.instance) {
|
|
38
|
+
TimerRegistry.instance = new TimerRegistry();
|
|
39
|
+
}
|
|
40
|
+
return TimerRegistry.instance;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Register global shutdown handlers (only once)
|
|
44
|
+
*/
|
|
45
|
+
registerGlobalShutdownHandlers() {
|
|
46
|
+
if (this.shutdownHandlersRegistered)
|
|
47
|
+
return;
|
|
48
|
+
const shutdownHandler = async (signal) => {
|
|
49
|
+
if (this.isShuttingDown)
|
|
50
|
+
return;
|
|
51
|
+
this.isShuttingDown = true;
|
|
52
|
+
this.logger.info(`Received ${signal}, cleaning up timers...`);
|
|
53
|
+
await this.cleanup();
|
|
54
|
+
};
|
|
55
|
+
// Use once() to avoid listener accumulation
|
|
56
|
+
process.once('beforeExit', () => shutdownHandler('beforeExit'));
|
|
57
|
+
process.once('SIGTERM', () => shutdownHandler('SIGTERM'));
|
|
58
|
+
process.once('SIGINT', () => shutdownHandler('SIGINT'));
|
|
59
|
+
this.shutdownHandlersRegistered = true;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Register a named interval
|
|
63
|
+
*
|
|
64
|
+
* @param id Unique identifier for the interval
|
|
65
|
+
* @param callback Function to execute
|
|
66
|
+
* @param ms Interval in milliseconds
|
|
67
|
+
* @param unref If true, don't keep the process alive for this timer (default: true)
|
|
68
|
+
* @returns The NodeJS.Timeout object
|
|
69
|
+
*/
|
|
70
|
+
registerInterval(id, callback, ms, unref = true) {
|
|
71
|
+
// Clear existing interval with same id
|
|
72
|
+
this.clearInterval(id);
|
|
73
|
+
const wrappedCallback = async () => {
|
|
74
|
+
try {
|
|
75
|
+
await callback();
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
this.logger.error(`Interval ${id} error:`, error);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const timer = setInterval(wrappedCallback, ms);
|
|
82
|
+
if (unref)
|
|
83
|
+
timer.unref();
|
|
84
|
+
const info = {
|
|
85
|
+
id,
|
|
86
|
+
type: 'interval',
|
|
87
|
+
timer,
|
|
88
|
+
createdAt: Date.now(),
|
|
89
|
+
callback: callback.name || 'anonymous'
|
|
90
|
+
};
|
|
91
|
+
this.intervals.set(id, info);
|
|
92
|
+
this.logger.debug(`Registered interval: ${id} (${ms}ms)`);
|
|
93
|
+
return timer;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Register a named timeout
|
|
97
|
+
*
|
|
98
|
+
* @param id Unique identifier for the timeout
|
|
99
|
+
* @param callback Function to execute
|
|
100
|
+
* @param ms Delay in milliseconds
|
|
101
|
+
* @returns The NodeJS.Timeout object
|
|
102
|
+
*/
|
|
103
|
+
registerTimeout(id, callback, ms) {
|
|
104
|
+
// Clear existing timeout with same id
|
|
105
|
+
this.clearTimeout(id);
|
|
106
|
+
const wrappedCallback = async () => {
|
|
107
|
+
this.timeouts.delete(id);
|
|
108
|
+
try {
|
|
109
|
+
await callback();
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
this.logger.error(`Timeout ${id} error:`, error);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const timer = setTimeout(wrappedCallback, ms);
|
|
116
|
+
const info = {
|
|
117
|
+
id,
|
|
118
|
+
type: 'timeout',
|
|
119
|
+
timer,
|
|
120
|
+
createdAt: Date.now(),
|
|
121
|
+
callback: callback.name || 'anonymous'
|
|
122
|
+
};
|
|
123
|
+
this.timeouts.set(id, info);
|
|
124
|
+
this.logger.debug(`Registered timeout: ${id} (${ms}ms)`);
|
|
125
|
+
return timer;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Clear a named interval
|
|
129
|
+
* @param id The interval identifier
|
|
130
|
+
*/
|
|
131
|
+
clearInterval(id) {
|
|
132
|
+
const info = this.intervals.get(id);
|
|
133
|
+
if (info) {
|
|
134
|
+
clearInterval(info.timer);
|
|
135
|
+
this.intervals.delete(id);
|
|
136
|
+
this.logger.debug(`Cleared interval: ${id}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Clear a named timeout
|
|
141
|
+
* @param id The timeout identifier
|
|
142
|
+
*/
|
|
143
|
+
clearTimeout(id) {
|
|
144
|
+
const info = this.timeouts.get(id);
|
|
145
|
+
if (info) {
|
|
146
|
+
clearTimeout(info.timer);
|
|
147
|
+
this.timeouts.delete(id);
|
|
148
|
+
this.logger.debug(`Cleared timeout: ${id}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Check if an interval exists
|
|
153
|
+
* @param id The interval identifier
|
|
154
|
+
*/
|
|
155
|
+
hasInterval(id) {
|
|
156
|
+
return this.intervals.has(id);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Check if a timeout exists
|
|
160
|
+
* @param id The timeout identifier
|
|
161
|
+
*/
|
|
162
|
+
hasTimeout(id) {
|
|
163
|
+
return this.timeouts.has(id);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Register a shutdown handler
|
|
167
|
+
* Called during cleanup() in reverse order of registration
|
|
168
|
+
*
|
|
169
|
+
* @param handler Async function to call during shutdown
|
|
170
|
+
*/
|
|
171
|
+
registerShutdownHandler(handler) {
|
|
172
|
+
this.shutdownHandlers.push(handler);
|
|
173
|
+
this.logger.debug(`Registered shutdown handler (total: ${this.shutdownHandlers.length})`);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Remove a shutdown handler
|
|
177
|
+
* @param handler The handler to remove
|
|
178
|
+
*/
|
|
179
|
+
removeShutdownHandler(handler) {
|
|
180
|
+
const idx = this.shutdownHandlers.indexOf(handler);
|
|
181
|
+
if (idx > -1) {
|
|
182
|
+
this.shutdownHandlers.splice(idx, 1);
|
|
183
|
+
this.logger.debug(`Removed shutdown handler (total: ${this.shutdownHandlers.length})`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Cleanup all timers and run shutdown handlers
|
|
188
|
+
*/
|
|
189
|
+
async cleanup() {
|
|
190
|
+
this.logger.info('Starting cleanup...');
|
|
191
|
+
// Clear all intervals
|
|
192
|
+
const intervalCount = this.intervals.size;
|
|
193
|
+
this.intervals.forEach((info) => {
|
|
194
|
+
clearInterval(info.timer);
|
|
195
|
+
});
|
|
196
|
+
this.intervals.clear();
|
|
197
|
+
// Clear all timeouts
|
|
198
|
+
const timeoutCount = this.timeouts.size;
|
|
199
|
+
this.timeouts.forEach((info) => {
|
|
200
|
+
clearTimeout(info.timer);
|
|
201
|
+
});
|
|
202
|
+
this.timeouts.clear();
|
|
203
|
+
// Run shutdown handlers in reverse order (LIFO)
|
|
204
|
+
const handlerCount = this.shutdownHandlers.length;
|
|
205
|
+
const handlers = [...this.shutdownHandlers].reverse();
|
|
206
|
+
this.shutdownHandlers = [];
|
|
207
|
+
for (const handler of handlers) {
|
|
208
|
+
try {
|
|
209
|
+
await handler();
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
this.logger.error('Shutdown handler error:', error);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
this.logger.info(`Cleanup complete: ${intervalCount} intervals, ${timeoutCount} timeouts, ${handlerCount} handlers`);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Get statistics about registered timers
|
|
219
|
+
*/
|
|
220
|
+
getStats() {
|
|
221
|
+
return {
|
|
222
|
+
intervals: this.intervals.size,
|
|
223
|
+
timeouts: this.timeouts.size,
|
|
224
|
+
shutdownHandlers: this.shutdownHandlers.length,
|
|
225
|
+
intervalIds: Array.from(this.intervals.keys()),
|
|
226
|
+
timeoutIds: Array.from(this.timeouts.keys())
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Get detailed information about all timers
|
|
231
|
+
*/
|
|
232
|
+
getDetailedStats() {
|
|
233
|
+
const now = Date.now();
|
|
234
|
+
return {
|
|
235
|
+
intervals: Array.from(this.intervals.values()).map(info => ({
|
|
236
|
+
id: info.id,
|
|
237
|
+
ageMs: now - info.createdAt,
|
|
238
|
+
callback: info.callback
|
|
239
|
+
})),
|
|
240
|
+
timeouts: Array.from(this.timeouts.values()).map(info => ({
|
|
241
|
+
id: info.id,
|
|
242
|
+
ageMs: now - info.createdAt,
|
|
243
|
+
callback: info.callback
|
|
244
|
+
})),
|
|
245
|
+
shutdownHandlerCount: this.shutdownHandlers.length
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Clear all timers by prefix
|
|
250
|
+
* Useful for cleaning up all timers from a specific component
|
|
251
|
+
*
|
|
252
|
+
* @param prefix The prefix to match (e.g., 'mcp-' clears 'mcp-auth', 'mcp-metrics', etc.)
|
|
253
|
+
*/
|
|
254
|
+
clearByPrefix(prefix) {
|
|
255
|
+
let intervalCount = 0;
|
|
256
|
+
let timeoutCount = 0;
|
|
257
|
+
// Collect keys to clear (can't modify while iterating)
|
|
258
|
+
const intervalsToClear = [];
|
|
259
|
+
const timeoutsToClear = [];
|
|
260
|
+
this.intervals.forEach((_, id) => {
|
|
261
|
+
if (id.startsWith(prefix)) {
|
|
262
|
+
intervalsToClear.push(id);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
this.timeouts.forEach((_, id) => {
|
|
266
|
+
if (id.startsWith(prefix)) {
|
|
267
|
+
timeoutsToClear.push(id);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
// Clear collected timers
|
|
271
|
+
intervalsToClear.forEach(id => {
|
|
272
|
+
this.clearInterval(id);
|
|
273
|
+
intervalCount++;
|
|
274
|
+
});
|
|
275
|
+
timeoutsToClear.forEach(id => {
|
|
276
|
+
this.clearTimeout(id);
|
|
277
|
+
timeoutCount++;
|
|
278
|
+
});
|
|
279
|
+
this.logger.debug(`Cleared by prefix '${prefix}': ${intervalCount} intervals, ${timeoutCount} timeouts`);
|
|
280
|
+
return { intervals: intervalCount, timeouts: timeoutCount };
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
exports.TimerRegistry = TimerRegistry;
|
|
284
|
+
/**
|
|
285
|
+
* Singleton instance of TimerRegistry
|
|
286
|
+
* Use this for all timer management in snow-flow
|
|
287
|
+
*/
|
|
288
|
+
exports.timerRegistry = TimerRegistry.getInstance();
|
|
289
|
+
//# sourceMappingURL=timer-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer-registry.js","sourceRoot":"","sources":["../../src/utils/timer-registry.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAEH,2CAAqC;AAkBrC;;;;;;;;GAQG;AACH,MAAa,aAAa;IASxB;QAPQ,cAAS,GAA2B,IAAI,GAAG,EAAE,CAAC;QAC9C,aAAQ,GAA2B,IAAI,GAAG,EAAE,CAAC;QAC7C,qBAAgB,GAAsB,EAAE,CAAC;QAEzC,mBAAc,GAAG,KAAK,CAAC;QACvB,+BAA0B,GAAG,KAAK,CAAC;QAGzC,IAAI,CAAC,MAAM,GAAG,IAAI,kBAAM,CAAC,eAAe,CAAC,CAAC;QAC1C,IAAI,CAAC,8BAA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AAE;YAC3B,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;YACtB,YAAY,EAAE,CAAC;QACjB,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,MAAM,MAAM,aAAa,eAAe,YAAY,WAAW,CAAC,CAAC;QAEzG,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;IAC9D,CAAC;CACF;AA5TD,sCA4TC;AAED;;;GAGG;AACU,QAAA,aAAa,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "snow-flow",
|
|
3
|
-
"version": "8.39.
|
|
3
|
+
"version": "8.39.2",
|
|
4
4
|
"description": "ServiceNow development with SnowCode - 75+ LLM providers (Claude, GPT, Gemini, Llama, Mistral, DeepSeek, Groq, Ollama) • 395 Optimized Tools • 2 MCP Servers • Multi-agent orchestration • Use ANY AI coding assistant (ML tools moved to Enterprise)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "commonjs",
|