29 lines
1.1 KiB
JavaScript
29 lines
1.1 KiB
JavaScript
const { createApp } = require('./app');
|
|
const { runAlertCycle } = require('./services/alerts');
|
|
const { runScheduledSync } = require('./services/workday');
|
|
|
|
const PORT = Number(process.env.PORT || process.env.MIXEDASSETS_PORT || 3000);
|
|
const app = createApp();
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`MixedAssets API listening on http://localhost:${PORT}`);
|
|
});
|
|
|
|
// Periodically scan for due/expiring items and email digests. These are no-ops
|
|
// unless alerts are enabled and SMTP is configured. Runs after boot, then twice daily.
|
|
function scheduleAlertCycle() {
|
|
const tick = () => runAlertCycle(null).catch((error) => console.error('Alert cycle failed:', error.message));
|
|
setTimeout(tick, 30_000).unref();
|
|
setInterval(tick, 12 * 60 * 60 * 1000).unref();
|
|
}
|
|
|
|
// Hourly check for a due automatic Workday sync (respects the configured interval).
|
|
function scheduleWorkdaySync() {
|
|
const tick = () => runScheduledSync().catch((error) => console.error('Workday sync failed:', error.message));
|
|
setTimeout(tick, 60_000).unref();
|
|
setInterval(tick, 60 * 60 * 1000).unref();
|
|
}
|
|
|
|
scheduleAlertCycle();
|
|
scheduleWorkdaySync();
|