Generate Next Timeslot for recurring interval

pull/1213/head
Louis Lam 2 years ago
parent 268cbdbf8d
commit 0b8d4cdaac

@ -65,6 +65,8 @@ CREATE INDEX [active_timeslot_index] ON [maintenance_timeslot] (
[end_date] DESC [end_date] DESC
); );
CREATE INDEX [generated_next_index] ON [maintenance_timeslot] ([generated_next]);
-- monitor_maintenance -- monitor_maintenance
CREATE TABLE monitor_maintenance ( CREATE TABLE monitor_maintenance (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,

@ -1721,6 +1721,8 @@ async function shutdownFunction(signal) {
log.info("server", "Shutdown requested"); log.info("server", "Shutdown requested");
log.info("server", "Called signal: " + signal); log.info("server", "Called signal: " + signal);
await server.stop();
log.info("server", "Stopping all monitors"); log.info("server", "Stopping all monitors");
for (let id in server.monitorList) { for (let id in server.monitorList) {
let monitor = server.monitorList[id]; let monitor = server.monitorList[id];

@ -45,6 +45,8 @@ class UptimeKumaServer {
*/ */
indexHTML = ""; indexHTML = "";
generateMaintenanceTimeslotsInterval = undefined;
static getInstance(args) { static getInstance(args) {
if (UptimeKumaServer.instance == null) { if (UptimeKumaServer.instance == null) {
UptimeKumaServer.instance = new UptimeKumaServer(args); UptimeKumaServer.instance = new UptimeKumaServer(args);
@ -90,6 +92,9 @@ class UptimeKumaServer {
dayjs.tz.setDefault(process.env.TZ); dayjs.tz.setDefault(process.env.TZ);
log.debug("DEBUG", "Timezone: " + process.env.TZ); log.debug("DEBUG", "Timezone: " + process.env.TZ);
log.debug("DEBUG", "Current Time: " + dayjs.tz().format()); log.debug("DEBUG", "Current Time: " + dayjs.tz().format());
await this.generateMaintenanceTimeslots();
this.generateMaintenanceTimeslotsInterval = setInterval(this.generateMaintenanceTimeslots, 60 * 1000);
} }
async sendMonitorList(socket) { async sendMonitorList(socket) {
@ -213,8 +218,28 @@ class UptimeKumaServer {
process.env.TZ = timezone; process.env.TZ = timezone;
dayjs.tz.setDefault(timezone); dayjs.tz.setDefault(timezone);
} }
async generateMaintenanceTimeslots() {
let list = await R.find("maintenance_timeslot", " generated_next = 0 AND start_date <= DATETIME('now') ");
for (let maintenanceTimeslot of list) {
let maintenance = await maintenanceTimeslot.maintenance;
await MaintenanceTimeslot.generateTimeslot(maintenance, maintenanceTimeslot.end_date, false);
maintenanceTimeslot.generated_next = true;
await R.store(maintenanceTimeslot);
}
}
async stop() {
clearTimeout(this.generateMaintenanceTimeslotsInterval);
}
} }
module.exports = { module.exports = {
UptimeKumaServer UptimeKumaServer
}; };
// Must be at the end
const MaintenanceTimeslot = require("./model/maintenance_timeslot");

Loading…
Cancel
Save