Skip to content

Commit 6bb8c74

Browse files
committed
refactor
1 parent 5c652b6 commit 6bb8c74

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

packages/core/src/shared/utilities/processUtils.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ interface Tracker<P, T> {
6767
delete(id: P): void
6868
has(item: T): boolean
6969
size(): number
70-
cleanUp(): void
71-
monitor(): void | Promise<void>
7270
clear(): void
7371
}
7472

@@ -79,7 +77,7 @@ export interface ProcessStats {
7977
cpu: number
8078
elapsed: number
8179
}
82-
export class ChildProcessTracker implements Tracker<number, ChildProcess> {
80+
export class ChildProcessTracker {
8381
static readonly pollingInterval: number = 10000
8482
static readonly thresholds: ProcessStats = {
8583
memory: 100 * 1024 * 1024, // 100 MB
@@ -93,7 +91,7 @@ export class ChildProcessTracker implements Tracker<number, ChildProcess> {
9391
this.#pids = new PollingSet(ChildProcessTracker.pollingInterval, () => this.monitor())
9492
}
9593

96-
public cleanUp() {
94+
private cleanUp() {
9795
const terminatedProcesses = Array.from(this.#pids.values()).filter(
9896
(pid: number) => this.#processByPid.get(pid)?.stopped
9997
)
@@ -102,7 +100,7 @@ export class ChildProcessTracker implements Tracker<number, ChildProcess> {
102100
}
103101
}
104102

105-
public async monitor() {
103+
private async monitor() {
106104
this.cleanUp()
107105
getLogger().debug(`Active running processes size: ${this.#pids.size}`)
108106

@@ -148,6 +146,11 @@ export class ChildProcessTracker implements Tracker<number, ChildProcess> {
148146
return this.#pids.has(childProcess.pid())
149147
}
150148

149+
public clear() {
150+
this.#pids.clear()
151+
this.#processByPid.clear()
152+
}
153+
151154
public async getUsage(pid: number): Promise<ProcessStats> {
152155
const stats = await pidusage(pid)
153156
return {
@@ -156,11 +159,6 @@ export class ChildProcessTracker implements Tracker<number, ChildProcess> {
156159
elapsed: stats.elapsed,
157160
}
158161
}
159-
160-
public clear() {
161-
this.#pids.clear()
162-
this.#processByPid.clear()
163-
}
164162
}
165163

166164
/**

0 commit comments

Comments
 (0)