cronjob de manejo de invitados listo
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { createApp } from './src/app.js';
|
||||
import { ensureSchema } from './src/services/db.js';
|
||||
import { ensureSchema, disableGuestsFromYesterday } from './src/services/db.js';
|
||||
|
||||
const app = createApp();
|
||||
const port = process.env.PORT || 3000;
|
||||
@@ -13,3 +13,24 @@ try {
|
||||
app.listen(port, () => {
|
||||
console.log(`Node RADIUS REST API listening on :${port}`);
|
||||
});
|
||||
|
||||
// Schedule daily guest disable at 4:00 AM America/Tegucigalpa (UTC-6 -> 10:00 UTC)
|
||||
function scheduleGuestJob() {
|
||||
const now = new Date();
|
||||
const next = new Date(now);
|
||||
next.setUTCHours(10, 0, 0, 0); // 10:00 UTC == 4:00 local (UTC-6)
|
||||
if (next <= now) next.setUTCDate(next.getUTCDate() + 1);
|
||||
const delay = next - now;
|
||||
setTimeout(async function run() {
|
||||
try {
|
||||
const { count } = await disableGuestsFromYesterday();
|
||||
if (count) console.log(`[guest-cron] Disabled ${count} invitado users from yesterday`);
|
||||
} catch (e) {
|
||||
console.error('[guest-cron] Error:', e?.message || e);
|
||||
} finally {
|
||||
scheduleGuestJob();
|
||||
}
|
||||
}, delay);
|
||||
}
|
||||
|
||||
scheduleGuestJob();
|
||||
|
||||
Reference in New Issue
Block a user