This commit is contained in:
2024-06-17 18:17:36 +05:00
parent 211f206e86
commit 7f9afc592c
5 changed files with 26 additions and 31 deletions
+9 -8
View File
@@ -54,6 +54,7 @@ app.get("/start", async (req, res) => {
const location = req.query.location;
const buildName = req.query.build;
const ownerIp = req.headers["x-real-ip"];
const endAt = req.query.endAt;
let type = req.query.type;
console.log("location", location);
console.log("buildName", buildName);
@@ -63,7 +64,6 @@ app.get("/start", async (req, res) => {
if (type !== "prod") {
type = "demo";
}
console.log("type", type);
const build = await getBuild(buildName);
if (!build) {
return res.json({ error: "Build not found" });
@@ -74,8 +74,6 @@ app.get("/start", async (req, res) => {
buildName,
type,
});
console.log("type", type);
console.log("activeSessionsWithBuild", activeSessionsWithBuild);
if (type === "demo" &&
build.demoLaunchLimit &&
activeSessionsWithBuild.length >= build.demoLaunchLimit) {
@@ -98,13 +96,14 @@ app.get("/start", async (req, res) => {
}
const sessionServerUrl = `https://${location}.sess.stream.graff.tech/${sessionServer.name}`;
// const sessionServerUrl = "http://localhost:3000";
console.log(`${sessionServerUrl}/start`);
console.log("endAt", endAt);
try {
const result = await got_cjs_1.default
.post(`${sessionServerUrl}/start`, {
json: {
buildName,
ownerIp,
endAt,
},
})
.json();
@@ -197,7 +196,7 @@ async function checkScheduledSessions() {
if (!scheduledSessions.length)
return;
for (const session of scheduledSessions) {
if ((0, date_fns_1.isAfter)(new Date(), (0, date_fns_1.parseISO)(session.startAt)) &&
if ((0, date_fns_1.isAfter)(new Date(), new Date(session.startAt)) &&
!session.activeSessionId) {
console.log("session.buildId", session.buildId);
const { build } = await got_cjs_1.default
@@ -205,7 +204,7 @@ async function checkScheduledSessions() {
.json();
console.log("build", build);
const result = await got_cjs_1.default
.get(`https://coord.graff.tech/start?build=${build}&location=a1`)
.get(`https://coord.graff.tech/start?build=${build}&location=a1&type=prod&endAt=${session.endAt}`)
.json();
if (!result.stream) {
console.log("Not result.stream");
@@ -220,9 +219,11 @@ async function checkScheduledSessions() {
.json();
console.log("result2: ", result2);
}
else if ((0, date_fns_1.isAfter)(new Date(), (0, date_fns_1.parseISO)(session.endAt))) {
else if ((0, date_fns_1.isAfter)(new Date(), new Date(session.endAt))) {
const result = await got_cjs_1.default
.post(`https://coord.graff.tech/active_sessions/${session.activeSessionId}/end`)
.post(`https://coord.graff.tech/end`, {
json: { activeSessionId: session.activeSessionId },
})
.json();
console.log("CRON End active session: ", result);
}
+3
View File
@@ -32,6 +32,9 @@ const activeSessionSchema = new mongoose_1.Schema({
connectedPlayersCount: {
type: Number,
},
endAt: {
type: Date,
},
}, {
timestamps: true,
toJSON: { virtuals: true },
+11 -12
View File
@@ -34,6 +34,7 @@ app.get("/start", async (req, res) => {
const location = req.query.location as string;
const buildName = req.query.build as string;
const ownerIp = req.headers["x-real-ip"];
const endAt = req.query.endAt as string;
let type = req.query.type as string;
console.log("location", location);
@@ -47,8 +48,6 @@ app.get("/start", async (req, res) => {
type = "demo";
}
console.log("type", type);
const build = await getBuild(buildName);
if (!build) {
@@ -63,9 +62,6 @@ app.get("/start", async (req, res) => {
type,
});
console.log("type", type);
console.log("activeSessionsWithBuild", activeSessionsWithBuild);
if (
type === "demo" &&
build.demoLaunchLimit &&
@@ -99,7 +95,7 @@ app.get("/start", async (req, res) => {
const sessionServerUrl = `https://${location}.sess.stream.graff.tech/${sessionServer.name}`;
// const sessionServerUrl = "http://localhost:3000";
console.log(`${sessionServerUrl}/start`);
console.log("endAt", endAt);
try {
const result: any = await got
@@ -107,6 +103,7 @@ app.get("/start", async (req, res) => {
json: {
buildName,
ownerIp,
endAt,
},
})
.json();
@@ -227,7 +224,7 @@ async function checkScheduledSessions() {
for (const session of scheduledSessions) {
if (
isAfter(new Date(), parseISO(session.startAt)) &&
isAfter(new Date(), new Date(session.startAt)) &&
!session.activeSessionId
) {
console.log("session.buildId", session.buildId);
@@ -238,7 +235,9 @@ async function checkScheduledSessions() {
console.log("build", build);
const result: any = await got
.get(`https://coord.graff.tech/start?build=${build}&location=a1`)
.get(
`https://coord.graff.tech/start?build=${build}&location=a1&type=prod&endAt=${session.endAt}`
)
.json();
if (!result.stream) {
@@ -255,11 +254,11 @@ async function checkScheduledSessions() {
.json();
console.log("result2: ", result2);
} else if (isAfter(new Date(), parseISO(session.endAt))) {
} else if (isAfter(new Date(), new Date(session.endAt))) {
const result = await got
.post(
`https://coord.graff.tech/active_sessions/${session.activeSessionId}/end`
)
.post(`https://coord.graff.tech/end`, {
json: { activeSessionId: session.activeSessionId },
})
.json();
console.log("CRON End active session: ", result);
+3
View File
@@ -32,6 +32,9 @@ const activeSessionSchema = new Schema(
connectedPlayersCount: {
type: Number,
},
endAt: {
type: Date,
},
},
{
timestamps: true,
-11
View File
@@ -1,11 +0,0 @@
import { Router } from "express";
const router = Router();
router.get("/", async (req, res) => {
res.json({ ok: 1 });
});
const testRouter = router;
export default testRouter;