re-organize files + setup more orchestration logic
This commit is contained in:
@ -1,10 +0,0 @@
|
||||
import { Server } from "socket.io";
|
||||
import { DefaultEventsMap } from "socket.io/dist/typed-events";
|
||||
|
||||
export function checkForInactivity(io: Server<DefaultEventsMap, DefaultEventsMap, DefaultEventsMap, any>) {
|
||||
io.fetchSockets().then(sockets => {
|
||||
if (sockets.length === 0) {
|
||||
console.log("No users have been connected for 15 seconds.");
|
||||
}
|
||||
});
|
||||
}
|
@ -18,6 +18,7 @@ import {
|
||||
getSandboxFiles,
|
||||
renameFile,
|
||||
saveFile,
|
||||
stopServer,
|
||||
} from "./utils"
|
||||
import { IDisposable, IPty, spawn } from "node-pty"
|
||||
import {
|
||||
@ -437,10 +438,12 @@ io.on("connection", async (socket) => {
|
||||
inactivityTimeout = setTimeout(() => {
|
||||
io.fetchSockets().then(sockets => {
|
||||
if (sockets.length === 0) {
|
||||
console.log("No users have been connected for 15 seconds.");
|
||||
// close server
|
||||
console.log("Closing server due to inactivity.");
|
||||
stopServer(data.sandboxId, data.userId)
|
||||
}
|
||||
});
|
||||
}, 15000);
|
||||
}, 60000);
|
||||
}
|
||||
|
||||
})
|
||||
|
@ -196,3 +196,16 @@ ${code}`,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export const stopServer = async (sandboxId: string, userId: string) => {
|
||||
await fetch("http://localhost:4001/stop", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
sandboxId,
|
||||
userId
|
||||
}),
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user