Skip to content

Commit

Permalink
feat(nitro-node): add default event handlers for nitro process
Browse files Browse the repository at this point in the history
  • Loading branch information
InNoobWeTrust committed Feb 27, 2024
1 parent 8e98728 commit 0c21b29
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
25 changes: 24 additions & 1 deletion nitro-node/src/nitro.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from "node:fs";
import path from "node:path";
import net from "node:net";
import stream from "node:stream";
import { ChildProcessWithoutNullStreams, spawn } from "node:child_process";
import tcpPortUsed from "tcp-port-used";
Expand Down Expand Up @@ -54,7 +55,29 @@ const getNitroProcessInfo = (subprocess: any): NitroProcessInfo => ({
});
const getCurrentNitroProcessInfo = () => getNitroProcessInfo(subprocess);
// Default event handler: do nothing
let processEventHandler: NitroProcessEventHandler = {};
let processEventHandler: NitroProcessEventHandler = {
close: (code: number, signal: string) => {
log(`[NITRO]::Debug: Nitro process closed with code ${code} and signal ${signal}`);
},
disconnect: () => {
log("[NITRO]::Debug: Nitro process disconnected");
},
error: (e: Error) => {
log(`[NITRO]::Error: Nitro process error: ${JSON.stringify(e)}`);
},
exit: (code: number, signal: string) => {
log(`[NITRO]::Debug: Nitro process exited with code ${code} and signal ${signal}`);
},
message: (
message: object,
sendHandle: net.Socket | net.Server | undefined,
) => {
log(`[NITRO]::Debug: Nitro process message: ${JSON.stringify(message)}`);
},
spawn: () => {
log("[NITRO]::Debug: Nitro process spawned");
},
};
// Default stdio handler: log stdout and stderr
let processStdioHandler: NitroProcessStdioHanler = {
stdout: (stdout: stream.Readable | null | undefined) => {
Expand Down
4 changes: 2 additions & 2 deletions nitro-node/test/nitro-process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ describe("Manage nitro process", () => {
// Stop nitro
await stopModel();
},
// Set timeout to 1 minutes
1 * 60 * 1000,
// Set timeout to 5 minutes
5 * 60 * 1000,
);
describe("search model file by magic number", () => {
// Rename model file before test
Expand Down

0 comments on commit 0c21b29

Please sign in to comment.