Generate Next Timeslot for recurring interval
This commit is contained in:
parent
268cbdbf8d
commit
0b8d4cdaac
|
@ -65,6 +65,8 @@ CREATE INDEX [active_timeslot_index] ON [maintenance_timeslot] (
|
|||
[end_date] DESC
|
||||
);
|
||||
|
||||
CREATE INDEX [generated_next_index] ON [maintenance_timeslot] ([generated_next]);
|
||||
|
||||
-- monitor_maintenance
|
||||
CREATE TABLE monitor_maintenance (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
|
|
|
@ -1721,6 +1721,8 @@ async function shutdownFunction(signal) {
|
|||
log.info("server", "Shutdown requested");
|
||||
log.info("server", "Called signal: " + signal);
|
||||
|
||||
await server.stop();
|
||||
|
||||
log.info("server", "Stopping all monitors");
|
||||
for (let id in server.monitorList) {
|
||||
let monitor = server.monitorList[id];
|
||||
|
|
|
@ -45,6 +45,8 @@ class UptimeKumaServer {
|
|||
*/
|
||||
indexHTML = "";
|
||||
|
||||
generateMaintenanceTimeslotsInterval = undefined;
|
||||
|
||||
static getInstance(args) {
|
||||
if (UptimeKumaServer.instance == null) {
|
||||
UptimeKumaServer.instance = new UptimeKumaServer(args);
|
||||
|
@ -90,6 +92,9 @@ class UptimeKumaServer {
|
|||
dayjs.tz.setDefault(process.env.TZ);
|
||||
log.debug("DEBUG", "Timezone: " + process.env.TZ);
|
||||
log.debug("DEBUG", "Current Time: " + dayjs.tz().format());
|
||||
|
||||
await this.generateMaintenanceTimeslots();
|
||||
this.generateMaintenanceTimeslotsInterval = setInterval(this.generateMaintenanceTimeslots, 60 * 1000);
|
||||
}
|
||||
|
||||
async sendMonitorList(socket) {
|
||||
|
@ -213,8 +218,28 @@ class UptimeKumaServer {
|
|||
process.env.TZ = 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 = {
|
||||
UptimeKumaServer
|
||||
};
|
||||
|
||||
// Must be at the end
|
||||
const MaintenanceTimeslot = require("./model/maintenance_timeslot");
|
||||
|
|
Loading…
Reference in New Issue