feat: implement scenario caching and hot-reloading

Signed-off-by: Abhinav Sinha <[email protected]>
This commit is contained in:
Abhinav Sinha
2026-06-15 15:28:53 +05:30
parent 8489544981
commit ab2403e914
4 changed files with 140 additions and 3 deletions
+29 -2
View File
@@ -90,12 +90,28 @@ function loadJsonDir(dir) {
.map(f => JSON.parse(fs.readFileSync(path.join(dir, f), 'utf8')));
}
let scenariosCache = [];
let bundlesCache = [];
function reloadCache() {
try {
scenariosCache = loadJsonDir(SCENARIOS_DIR);
bundlesCache = loadJsonDir(BUNDLES_DIR);
console.log(`Loaded ${scenariosCache.length} scenarios and ${bundlesCache.length} bundles into cache.`);
} catch (e) {
console.error('Failed to reload cache:', e.message);
}
}
// Initial cache populate
reloadCache();
function loadScenarios() {
return loadJsonDir(SCENARIOS_DIR);
return scenariosCache;
}
function loadBundles() {
return loadJsonDir(BUNDLES_DIR);
return bundlesCache;
}
async function runCommand(cmd, timeoutMs = 15000) {
@@ -466,6 +482,17 @@ app.post('/api/progress/reset/:id', (req, res) => {
res.json({ ok: true });
});
// POST /api/cache/reload — reload scenarios and bundles cache
app.post('/api/cache/reload', (req, res) => {
reloadCache();
res.json({
ok: true,
message: 'Cache reloaded successfully',
scenarios_count: loadScenarios().length,
bundles_count: loadBundles().length
});
});
// GET /api/health
app.get('/api/health', async (req, res) => {
const kube = await runCommand('kubectl cluster-info --request-timeout=3s 2>&1 | head -1');