diff --git a/dist/index.js b/dist/index.js index 392b80c..d8e33f4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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); } diff --git a/dist/models/ActiveSession.js b/dist/models/ActiveSession.js index 605cded..3d6c804 100644 --- a/dist/models/ActiveSession.js +++ b/dist/models/ActiveSession.js @@ -32,6 +32,9 @@ const activeSessionSchema = new mongoose_1.Schema({ connectedPlayersCount: { type: Number, }, + endAt: { + type: Date, + }, }, { timestamps: true, toJSON: { virtuals: true }, diff --git a/src/index.ts b/src/index.ts index cbbb806..20d0573 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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); diff --git a/src/models/ActiveSession.ts b/src/models/ActiveSession.ts index 507e5b1..a490712 100644 --- a/src/models/ActiveSession.ts +++ b/src/models/ActiveSession.ts @@ -32,6 +32,9 @@ const activeSessionSchema = new Schema( connectedPlayersCount: { type: Number, }, + endAt: { + type: Date, + }, }, { timestamps: true, diff --git a/src/routes/test.ts b/src/routes/test.ts deleted file mode 100644 index 4b1ea5c..0000000 --- a/src/routes/test.ts +++ /dev/null @@ -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;