upd
This commit is contained in:
+33
-18
@@ -16,7 +16,7 @@ type Session = typeof sessionsTable.$inferSelect & {
|
||||
client: {
|
||||
name: string;
|
||||
phone: string;
|
||||
email?: string;
|
||||
email: string | null;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -95,28 +95,24 @@ async function addApps() {
|
||||
json,
|
||||
})
|
||||
.json();
|
||||
|
||||
console.log("Apps added");
|
||||
} catch (error) {
|
||||
// if (error instanceof HTTPError) {
|
||||
// console.error("Error sending installed apps:", error.response.body);
|
||||
// } else {
|
||||
// console.error((error as Error).message);
|
||||
// }
|
||||
// console.error("Error adding apps", error);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await addApps();
|
||||
console.log("Apps added");
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
// console.error("Error adding apps", error);
|
||||
}
|
||||
|
||||
async function getSessions() {
|
||||
const session = await db.query.sessionsTable.findFirst({
|
||||
return await db.query.sessionsTable.findFirst({
|
||||
where: and(
|
||||
eq(sessionsTable.serverId, serverInfo!.id),
|
||||
or(
|
||||
eq(sessionsTable.status, "started"),
|
||||
eq(sessionsTable.status, "starting"),
|
||||
eq(sessionsTable.status, "ending")
|
||||
)
|
||||
@@ -137,8 +133,6 @@ async function getSessions() {
|
||||
},
|
||||
orderBy: desc(sessionsTable.createdAt),
|
||||
});
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
async function startSession(session: Session) {
|
||||
@@ -179,14 +173,35 @@ async function endSession(session: Session) {
|
||||
}
|
||||
|
||||
async function scheduleSession() {
|
||||
const session = await getSessions();
|
||||
try {
|
||||
const session = await getSessions();
|
||||
|
||||
if (!session) return;
|
||||
if (!session) return;
|
||||
|
||||
if (session.status === "starting") {
|
||||
startSession(session);
|
||||
} else if (session.status === "ending") {
|
||||
endSession(session);
|
||||
if (session.status === "starting") {
|
||||
startSession(session);
|
||||
} else if (session.status === "ending") {
|
||||
endSession(session);
|
||||
} else if (session.status === "started") {
|
||||
const result = exec(
|
||||
`pwsh -c "Get-Process -Name ${session.app.fileName}"`
|
||||
);
|
||||
|
||||
result.stderr?.on("data", async (data) => {
|
||||
console.log(data.toString());
|
||||
|
||||
try {
|
||||
await db
|
||||
.update(sessionsTable)
|
||||
.set({ status: "ended" })
|
||||
.where(eq(sessionsTable.id, session.id));
|
||||
} catch (error) {
|
||||
console.error("Error ending session", error);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error scheduling session", error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user