This commit is contained in:
2024-06-06 18:15:03 +05:00
parent 3728d49ad9
commit 6f6555e1c1
3 changed files with 108 additions and 2 deletions
+46
View File
@@ -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("* * * * *", () => {
checkActiveSessions();
});
node_cron_1.default.schedule("* * * * *", () => {
checkScheduledSessions();
});