add persistent readiness health check

This commit is contained in:
2026-09-06 18:37:11 +03:00
parent b10546b81a
commit 11685867e2
4 changed files with 40 additions and 2 deletions
+24
View File
@@ -75,6 +75,26 @@ const PORT = process.env.PORT || 3001;
const ILAN_BASE = 'https://www.ilan.gov.tr';
const CORS_ORIGINS = String(process.env.CORS_ORIGINS || '').split(',').map(value => value.trim()).filter(Boolean);
function readiness() {
const directories = {
userData: process.env.IHALEIST_USER_DATA_DIR || path.join(__dirname, 'data'),
sharedData: process.env.IHALEIST_SHARED_DATA_DIR || path.join(__dirname, 'data'),
};
const checks = {};
let ready = true;
for (const [name, directory] of Object.entries(directories)) {
try {
fs.mkdirSync(directory, { recursive: true });
fs.accessSync(directory, fs.constants.R_OK | fs.constants.W_OK);
checks[name] = { ok: true };
} catch (error) {
ready = false;
checks[name] = { ok: false, error: error.code || 'EACCES' };
}
}
return { ready, checks };
}
function validateHealthPortfolio(value) {
if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('Firma profili geçersiz.');
const portfolio = value.scrapedCapabilities?.healthPortfolio;
@@ -1700,6 +1720,10 @@ const server = http.createServer(async (req, res) => {
}
if (url.pathname === '/api/health') return json(res, 200, { ok: true });
if (url.pathname === '/api/ready') {
const status = readiness();
return json(res, status.ready ? 200 : 503, { ok: status.ready, ...status });
}
if (url.pathname === '/api/health/sektor') {
const say = sektorZenginSayi();
const genel = (cache.tenders || []).filter((t) => t.sektor === 'Genel').length;