chore: clean dangling process on exit and relaunch

This commit is contained in:
Louis 2024-11-06 13:34:11 +07:00
parent 24b7d64efc
commit 56e35df84d
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2

View File

@ -50,12 +50,18 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine {
// Run the process watchdog
const systemInfo = await systemInformation()
await this.clean()
await executeOnMain(NODE, 'run', systemInfo)
this.queue.add(() => this.healthz())
window.addEventListener('beforeunload', () => {
this.clean()
})
}
onUnload(): void {
this.clean()
executeOnMain(NODE, 'dispose')
super.onUnload()
}
@ -132,6 +138,20 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine {
})
.then(() => {})
}
/**
* Clean cortex processes
* @returns
*/
clean(): Promise<any> {
return ky
.delete(`${CORTEX_API_URL}/processmanager/destroy`, {
timeout: 2000, // maximum 2 seconds
})
.catch(() => {
// Do nothing
})
}
}
/// Legacy