@@ -67,8 +67,6 @@ interface Tracker<P, T> {
67
67
delete ( id : P ) : void
68
68
has ( item : T ) : boolean
69
69
size ( ) : number
70
- cleanUp ( ) : void
71
- monitor ( ) : void | Promise < void >
72
70
clear ( ) : void
73
71
}
74
72
@@ -79,7 +77,7 @@ export interface ProcessStats {
79
77
cpu : number
80
78
elapsed : number
81
79
}
82
- export class ChildProcessTracker implements Tracker < number , ChildProcess > {
80
+ export class ChildProcessTracker {
83
81
static readonly pollingInterval : number = 10000
84
82
static readonly thresholds : ProcessStats = {
85
83
memory : 100 * 1024 * 1024 , // 100 MB
@@ -93,7 +91,7 @@ export class ChildProcessTracker implements Tracker<number, ChildProcess> {
93
91
this . #pids = new PollingSet ( ChildProcessTracker . pollingInterval , ( ) => this . monitor ( ) )
94
92
}
95
93
96
- public cleanUp ( ) {
94
+ private cleanUp ( ) {
97
95
const terminatedProcesses = Array . from ( this . #pids. values ( ) ) . filter (
98
96
( pid : number ) => this . #processByPid. get ( pid ) ?. stopped
99
97
)
@@ -102,7 +100,7 @@ export class ChildProcessTracker implements Tracker<number, ChildProcess> {
102
100
}
103
101
}
104
102
105
- public async monitor ( ) {
103
+ private async monitor ( ) {
106
104
this . cleanUp ( )
107
105
getLogger ( ) . debug ( `Active running processes size: ${ this . #pids. size } ` )
108
106
@@ -148,6 +146,11 @@ export class ChildProcessTracker implements Tracker<number, ChildProcess> {
148
146
return this . #pids. has ( childProcess . pid ( ) )
149
147
}
150
148
149
+ public clear ( ) {
150
+ this . #pids. clear ( )
151
+ this . #processByPid. clear ( )
152
+ }
153
+
151
154
public async getUsage ( pid : number ) : Promise < ProcessStats > {
152
155
const stats = await pidusage ( pid )
153
156
return {
@@ -156,11 +159,6 @@ export class ChildProcessTracker implements Tracker<number, ChildProcess> {
156
159
elapsed : stats . elapsed ,
157
160
}
158
161
}
159
-
160
- public clear ( ) {
161
- this . #pids. clear ( )
162
- this . #processByPid. clear ( )
163
- }
164
162
}
165
163
166
164
/**
0 commit comments