-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fix PP issues, add instancesManager, and process health checker
- Loading branch information
Showing
11 changed files
with
216 additions
and
349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import findProcess from 'find-process'; | ||
|
||
import { sleep } from '@/Utils/sleep'; | ||
import { OSU_REGEX } from '@/constants'; | ||
|
||
import { OsuInstance } from './Osu'; | ||
|
||
export class InstancesManager { | ||
osuInstances: { | ||
[key: number]: OsuInstance; | ||
}; | ||
|
||
constructor() { | ||
this.osuInstances = {}; | ||
} | ||
|
||
private onProcessDestroy(pid: number) { | ||
// FOOL PROTECTION | ||
if (!(pid in this.osuInstances)) { | ||
return; | ||
} | ||
|
||
delete this.osuInstances[pid]; | ||
} | ||
|
||
async runWatcher() { | ||
while (true) { | ||
const osuProcesses = await findProcess('name', OSU_REGEX); | ||
for (const process of osuProcesses) { | ||
if (process.pid in this.osuInstances) { | ||
// dont deploy not needed instances | ||
continue; | ||
} | ||
|
||
const osuInstance = new OsuInstance(process.pid); | ||
osuInstance.emitter.on('onDestroy', this.onProcessDestroy.bind(this)); | ||
osuInstance.emitter.on( | ||
'onResolveFailed', | ||
this.onProcessDestroy.bind(this) | ||
); | ||
|
||
this.osuInstances[process.pid] = osuInstance; | ||
osuInstance.start(); | ||
} | ||
|
||
await sleep(5000); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.