upd
This commit is contained in:
+33
-18
@@ -16,7 +16,7 @@ type Session = typeof sessionsTable.$inferSelect & {
|
|||||||
client: {
|
client: {
|
||||||
name: string;
|
name: string;
|
||||||
phone: string;
|
phone: string;
|
||||||
email?: string;
|
email: string | null;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -95,28 +95,24 @@ async function addApps() {
|
|||||||
json,
|
json,
|
||||||
})
|
})
|
||||||
.json();
|
.json();
|
||||||
|
|
||||||
console.log("Apps added");
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// if (error instanceof HTTPError) {
|
// console.error("Error adding apps", error);
|
||||||
// console.error("Error sending installed apps:", error.response.body);
|
|
||||||
// } else {
|
|
||||||
// console.error((error as Error).message);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await addApps();
|
await addApps();
|
||||||
|
console.log("Apps added");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
// console.error("Error adding apps", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSessions() {
|
async function getSessions() {
|
||||||
const session = await db.query.sessionsTable.findFirst({
|
return await db.query.sessionsTable.findFirst({
|
||||||
where: and(
|
where: and(
|
||||||
eq(sessionsTable.serverId, serverInfo!.id),
|
eq(sessionsTable.serverId, serverInfo!.id),
|
||||||
or(
|
or(
|
||||||
|
eq(sessionsTable.status, "started"),
|
||||||
eq(sessionsTable.status, "starting"),
|
eq(sessionsTable.status, "starting"),
|
||||||
eq(sessionsTable.status, "ending")
|
eq(sessionsTable.status, "ending")
|
||||||
)
|
)
|
||||||
@@ -137,8 +133,6 @@ async function getSessions() {
|
|||||||
},
|
},
|
||||||
orderBy: desc(sessionsTable.createdAt),
|
orderBy: desc(sessionsTable.createdAt),
|
||||||
});
|
});
|
||||||
|
|
||||||
return session;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startSession(session: Session) {
|
async function startSession(session: Session) {
|
||||||
@@ -179,14 +173,35 @@ async function endSession(session: Session) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function scheduleSession() {
|
async function scheduleSession() {
|
||||||
const session = await getSessions();
|
try {
|
||||||
|
const session = await getSessions();
|
||||||
|
|
||||||
if (!session) return;
|
if (!session) return;
|
||||||
|
|
||||||
if (session.status === "starting") {
|
if (session.status === "starting") {
|
||||||
startSession(session);
|
startSession(session);
|
||||||
} else if (session.status === "ending") {
|
} else if (session.status === "ending") {
|
||||||
endSession(session);
|
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