🎨 moved checkloop outside main loop function
This commit is contained in:
parent
3577f3df55
commit
806b3198a1
2 changed files with 22 additions and 13 deletions
30
app.js
30
app.js
|
@ -42,22 +42,26 @@ app.listen(4000);
|
|||
(async function () {
|
||||
for await (const time of setInterval(config.checkperiod * 10)) {
|
||||
console.log("Checking for spaces...");
|
||||
for (const space of spaces) {
|
||||
console.log(`Checking ${space.id}...`);
|
||||
let o = await checkSpace(space);
|
||||
console.log(`Space ${space.id} is ${o ? "open" : "closed"}`);
|
||||
if (o !== cache.get(space.id)) {
|
||||
cache.set(space.id, o);
|
||||
let update = await prisma.space.upsert({
|
||||
where: { id: space.id },
|
||||
update: { open: o },
|
||||
create: { id: space.id, open: o }
|
||||
});
|
||||
}
|
||||
}
|
||||
await loop();
|
||||
}
|
||||
})();
|
||||
|
||||
async function loop() {
|
||||
for (const space of spaces) {
|
||||
console.log(`Checking ${space.id}...`);
|
||||
let o = await checkSpace(space);
|
||||
console.log(`Space ${space.id} is ${o ? "open" : "closed"}`);
|
||||
if (o !== cache.get(space.id)) {
|
||||
cache.set(space.id, o);
|
||||
let update = await prisma.space.upsert({
|
||||
where: { id: space.id },
|
||||
update: { open: o },
|
||||
create: { id: space.id, open: o }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// HELPER FUNCTIONS
|
||||
async function checkSpace(space) {
|
||||
let response, data, open;
|
||||
|
|
|
@ -8,5 +8,10 @@
|
|||
"node-cache": "^5.1.2",
|
||||
"node-fetch": "2",
|
||||
"prisma": "^4.9.0"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node app.js",
|
||||
"generate": "npx prisma generate dev",
|
||||
"migrate": "npx prisma migrate"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue