upd
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
PORT=4000
|
PORT=4000
|
||||||
MONGO_URI=mongodb://root:p62Z!ZatgY25@194.26.138.94:27017
|
MONGO_URI=mongodb://root:p62Z!ZatgY25@194.26.138.94:27017
|
||||||
|
CRM_API_URL=https://crm.stream.graff.tech/api
|
||||||
Vendored
+46
@@ -189,6 +189,52 @@ async function checkActiveSessions() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async function checkScheduledSessions() {
|
||||||
|
try {
|
||||||
|
const scheduledSessions = await got_cjs_1.default
|
||||||
|
.get(`${process.env.CRM_API_URL}/scheduled_sessions`)
|
||||||
|
.json();
|
||||||
|
if (!scheduledSessions.length)
|
||||||
|
return;
|
||||||
|
for (const session of scheduledSessions) {
|
||||||
|
if ((0, date_fns_1.isAfter)(new Date(), (0, date_fns_1.parseISO)(session.startAt)) &&
|
||||||
|
!session.activeSessionId) {
|
||||||
|
console.log("session.buildId", session.buildId);
|
||||||
|
const { build } = await got_cjs_1.default
|
||||||
|
.get(`${process.env.CRM_API_URL}/builds/${session.buildId}`)
|
||||||
|
.json();
|
||||||
|
console.log("build", build);
|
||||||
|
const result = await got_cjs_1.default
|
||||||
|
.get(`https://coord.graff.tech/start?build=${build}&location=a1`)
|
||||||
|
.json();
|
||||||
|
if (!result.stream) {
|
||||||
|
console.log("Not result");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result2 = await got_cjs_1.default
|
||||||
|
.put(`${process.env.CRM_API_URL}/scheduled_sessions/${session.id}`, {
|
||||||
|
json: {
|
||||||
|
activeSessionId: result.stream,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.json();
|
||||||
|
console.log("CRON Start session: ", result2);
|
||||||
|
}
|
||||||
|
else if ((0, date_fns_1.isAfter)(new Date(), (0, date_fns_1.parseISO)(session.endAt))) {
|
||||||
|
const result = await got_cjs_1.default
|
||||||
|
.post(`https://coord.graff.tech/active_sessions/${session.activeSessionId}/end`)
|
||||||
|
.json();
|
||||||
|
console.log("CRON End active session: ", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log("Error: ", error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
node_cron_1.default.schedule("* * * * *", () => {
|
node_cron_1.default.schedule("* * * * *", () => {
|
||||||
checkActiveSessions();
|
checkActiveSessions();
|
||||||
});
|
});
|
||||||
|
node_cron_1.default.schedule("* * * * *", () => {
|
||||||
|
checkScheduledSessions();
|
||||||
|
});
|
||||||
|
|||||||
+60
-1
@@ -8,7 +8,7 @@ import got from "got-cjs";
|
|||||||
import Build from "./models/Build";
|
import Build from "./models/Build";
|
||||||
import { AccessToken } from "livekit-server-sdk";
|
import { AccessToken } from "livekit-server-sdk";
|
||||||
import cron from "node-cron";
|
import cron from "node-cron";
|
||||||
import { differenceInMinutes } from "date-fns";
|
import { differenceInMinutes, isAfter, parseISO } from "date-fns";
|
||||||
|
|
||||||
connectDB();
|
connectDB();
|
||||||
|
|
||||||
@@ -217,6 +217,65 @@ async function checkActiveSessions() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function checkScheduledSessions() {
|
||||||
|
try {
|
||||||
|
const scheduledSessions: any = await got
|
||||||
|
.get(`${process.env.CRM_API_URL}/scheduled_sessions`)
|
||||||
|
.json();
|
||||||
|
|
||||||
|
if (!scheduledSessions.length) return;
|
||||||
|
|
||||||
|
for (const session of scheduledSessions) {
|
||||||
|
if (
|
||||||
|
isAfter(new Date(), parseISO(session.startAt)) &&
|
||||||
|
!session.activeSessionId
|
||||||
|
) {
|
||||||
|
console.log("session.buildId", session.buildId);
|
||||||
|
const { build }: any = await got
|
||||||
|
.get(`${process.env.CRM_API_URL}/builds/${session.buildId}`)
|
||||||
|
.json();
|
||||||
|
|
||||||
|
console.log("build", build);
|
||||||
|
|
||||||
|
const result: any = await got
|
||||||
|
.get(`https://coord.graff.tech/start?build=${build}&location=a1`)
|
||||||
|
.json();
|
||||||
|
|
||||||
|
if (!result.stream) {
|
||||||
|
console.log("Not result");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result2 = await got
|
||||||
|
.put(`${process.env.CRM_API_URL}/scheduled_sessions/${session.id}`, {
|
||||||
|
json: {
|
||||||
|
startAt: session.startAt,
|
||||||
|
endAt: session.endAt,
|
||||||
|
activeSessionId: result.stream,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.json();
|
||||||
|
|
||||||
|
console.log("CRON Start session: ", result2);
|
||||||
|
} else if (isAfter(new Date(), parseISO(session.endAt))) {
|
||||||
|
const result = await got
|
||||||
|
.post(
|
||||||
|
`https://coord.graff.tech/active_sessions/${session.activeSessionId}/end`
|
||||||
|
)
|
||||||
|
.json();
|
||||||
|
|
||||||
|
console.log("CRON End active session: ", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Error: ", (error as Error).message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cron.schedule("* * * * *", () => {
|
cron.schedule("* * * * *", () => {
|
||||||
checkActiveSessions();
|
checkActiveSessions();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
cron.schedule("* * * * *", () => {
|
||||||
|
checkScheduledSessions();
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user