-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.js
46 lines (40 loc) · 1014 Bytes
/
monitor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const db = require("./db");
const api = require("./api");
const config = require("./config");
const logger = require("./logger");
const { startRecord } = require("./record");
async function check(room) {
if (room.recording) {
return;
}
let roomInfo = await api.getRoomInfo(room.roomId);
room = await db.roomsDao.update(room.roomId, {
lastChecked: new Date(),
uname: roomInfo.uname,
title: roomInfo.title,
});
if (roomInfo.live_status === 1) {
startRecord(room);
}
}
module.exports = async function monitor() {
await db.roomsDao.resetState();
let fn = async () => {
let rooms = await db.roomsDao.findAll();
let promises = [];
for (const room of rooms) {
promises.push(check(room));
}
try {
await Promise.all(promises);
logger.info("Check done");
} catch (error) {
logger.error("Check failed", error);
}
setTimeout(
fn,
config.checkInterval + Math.round(Math.random() * 30) * 1000
);
};
fn();
};