Skip to content

Commit

Permalink
Merge pull request janhq#975 from janhq/fix/kill_nitro
Browse files Browse the repository at this point in the history
feat: Kill nitro process with API - nitro 0.1.27
  • Loading branch information
hiro-v authored Dec 13, 2023
2 parents 3266014 + 2570113 commit b3405a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion extensions/inference-nitro-extension/bin/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.26
0.1.27
18 changes: 9 additions & 9 deletions extensions/inference-nitro-extension/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const NITRO_HTTP_SERVER_URL = `http://${LOCAL_HOST}:${PORT}`;
const NITRO_HTTP_LOAD_MODEL_URL = `${NITRO_HTTP_SERVER_URL}/inferences/llamacpp/loadmodel`;
const NITRO_HTTP_UNLOAD_MODEL_URL = `${NITRO_HTTP_SERVER_URL}/inferences/llamacpp/unloadModel`;
const NITRO_HTTP_VALIDATE_MODEL_URL = `${NITRO_HTTP_SERVER_URL}/inferences/llamacpp/modelstatus`;
const NITRO_HTTP_KILL_URL = `${NITRO_HTTP_SERVER_URL}/processmanager/destroy`;

// The subprocess instance for Nitro
let subprocess = null;
Expand Down Expand Up @@ -187,13 +188,15 @@ async function validateModelStatus(): Promise<ModelOperationResponse> {
* @returns A Promise that resolves when the subprocess is terminated successfully, or rejects with an error message if the subprocess fails to terminate.
*/
function killSubprocess(): Promise<void> {
if (subprocess) {
subprocess.kill();
fetch(NITRO_HTTP_KILL_URL, {
method: "DELETE",
}).catch((err) => {
console.error(err);
subprocess?.kill();
kill(PORT, "tcp").then(console.log).catch(console.log);
subprocess = null;
console.debug("Subprocess terminated.");
} else {
return kill(PORT, "tcp").then(console.log).catch(console.log);
}
});
return
}

/**
Expand All @@ -207,9 +210,6 @@ async function checkAndUnloadNitro() {
// Attempt to unload model
return fetch(NITRO_HTTP_UNLOAD_MODEL_URL, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
}).catch((err) => {
console.error(err);
// Fallback to kill the port
Expand Down

0 comments on commit b3405a6

Please sign in to comment.