From ec73351a9ba49e7567086ca9e17d0437c6bb3507 Mon Sep 17 00:00:00 2001 From: acegoal07 <39467245+acegoal07@users.noreply.github.com> Date: Tue, 22 Sep 2026 08:47:33 +0100 Subject: [PATCH] just housekeeping --- backend/enums/days.js | 4 ++- backend/schedule/scheduler.js | 29 ++++++++++---------- backend/services/dailyReport/dailyReport.js | 4 +-- backend/services/templater/templateInfo.json | 3 ++ backend/services/templater/templateIt.js | 4 +-- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/backend/enums/days.js b/backend/enums/days.js index 7f23552..5f32694 100644 --- a/backend/enums/days.js +++ b/backend/enums/days.js @@ -15,7 +15,9 @@ module.exports.dayFromIndex = (i) => (Number.isInteger(i) && DAYS[i]) || null; */ module.exports.indexFromDay = (s) => { const n = normalizeDay(s); - if (!n) return null; + if (!n) { + return null; + } const i = DAYS.indexOf(n); return i === -1 ? null : i; }; diff --git a/backend/schedule/scheduler.js b/backend/schedule/scheduler.js index 0dbd78b..34a322c 100644 --- a/backend/schedule/scheduler.js +++ b/backend/schedule/scheduler.js @@ -7,7 +7,7 @@ require('dotenv').config; * @returns {Promise} Team IDs */ async function getTeams(db) { - const response = await db + return db .collection('team') .find({}) .toArray() @@ -17,7 +17,6 @@ async function getTeams(db) { clustersPerDay: data.clusters_per_day })) ); - return response; } async function getTeamsOrderedByEffectiveCapacity(db) { @@ -77,7 +76,7 @@ async function isWorkingDay(db, date) { if (isWeekend) { return false; } - const response = await db.collection('closedDay').findOne({ day: day }); + const response = await db.collection('closedDay').findOne({ day }); return !response; } @@ -91,8 +90,8 @@ async function isWorkingDay(db, date) { async function generateScheduleForDay(db, date) { const teams = await getTeamsOrderedByEffectiveCapacity(db); - for (let i = 0; i < teams.length; i++) { - const team = teams[i]; + for (const element of teams) { + const team = element; // get pools for team const pools = await db.collection('teampool').find({ teamId: team.id }).toArray(); const poolIds = pools.map((p) => p.poolId); @@ -162,7 +161,7 @@ async function getNextPerson(db, teamId) { if (people.length === 0) { console.log('People assigned, unscheduling people...'); await db.collection('person').updateMany( - { teamId: teamId }, + { teamId }, { $set: { scheduled: false @@ -172,7 +171,7 @@ async function getNextPerson(db, teamId) { people = await db .collection('person') .find({ - teamId: teamId, + teamId, $or: [{ scheduled: false }, { scheduled: { $exists: false } }] }) .toArray(); @@ -228,8 +227,8 @@ async function generateUpToDay(db, date) { cursor.setDate(cursor.getDate() + 1); } - for (let i = 0; i < dates.length; i++) { - await generateScheduleForDay(db, dates[i]); + for (const element of dates) { + await generateScheduleForDay(db, element); } } @@ -290,9 +289,9 @@ async function formatScheduleForDay(db, date) { const scheduleDict = {}; - for (let i = 0; i < response.length; i++) { - const person = response[i].personId; - const cluster = response[i].clusterId; + for (const element of response) { + const person = element.personId; + const cluster = element.clusterId; (scheduleDict[person] ??= []).push(cluster); } @@ -320,7 +319,9 @@ async function handleStateChange(db) { day: { $gte: dateFrom } }); - if (!scheduleExists) return; + if (!scheduleExists) { + return; + } await db.collection('schedule').deleteMany({ day: { $gte: dateFrom } @@ -329,5 +330,5 @@ async function handleStateChange(db) { module.exports = { getScheduleForDay: formatScheduleForDay, - handleStateChange: handleStateChange + handleStateChange }; diff --git a/backend/services/dailyReport/dailyReport.js b/backend/services/dailyReport/dailyReport.js index 0bca4d8..a1a519a 100644 --- a/backend/services/dailyReport/dailyReport.js +++ b/backend/services/dailyReport/dailyReport.js @@ -51,7 +51,7 @@ module.exports = async (db) => { .then((res) => res.map(({ _id, clusterId }) => ({ id: _id.toString(), - clusterId: clusterId + clusterId })) ); @@ -80,7 +80,7 @@ module.exports = async (db) => { } await db.collection('overviewReport').insertOne({ - date: Long.fromNumber(new Date().getTime()), + date: Long.fromNumber(Date.now()), reports: reports.map((report) => report.id), missing: missingReports }); diff --git a/backend/services/templater/templateInfo.json b/backend/services/templater/templateInfo.json index 741f8f7..c897fd9 100644 --- a/backend/services/templater/templateInfo.json +++ b/backend/services/templater/templateInfo.json @@ -15,6 +15,9 @@ }, { "content": "Confirm home directories and shared filesystems are accessible." + }, + { + "content": "Check node accessibility\n```sh\nfor node in node{\n01..06\n}; do\necho -n \"$node: \"\nstart=$(date +%s%N)\nssh -o BatchMode=yes -o ConnectTimeout=5 \"$node\"\"exit\"\nend=$(date +%s%N)\necho \"$(( (end-start)/1000000 )) ms\"\ndone```" } ] }, diff --git a/backend/services/templater/templateIt.js b/backend/services/templater/templateIt.js index 8655a1c..8cc00fc 100644 --- a/backend/services/templater/templateIt.js +++ b/backend/services/templater/templateIt.js @@ -1,5 +1,5 @@ -const fs = require('fs/promises'); -const path = require('path'); +const fs = require('node:fs/promises'); +const path = require('node:path'); /** * Adds a basic template to the HPC cluster so it has generic instructions and methods