fix(notifications): changes to help improve the downtime check for greater than x only while active

This commit is contained in:
2025-06-09 19:26:36 -05:00
parent c0560770da
commit 94c3bb73b3
4 changed files with 63 additions and 58 deletions

View File

@@ -1,5 +1,6 @@
import { db } from "../../../../database/dbclient.js";
import { notifications } from "../../../../database/schema/notifications.js";
import { settings } from "../../../../database/schema/settings.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import type { JobInfo } from "../../../types/JobInfo.js";
import { createLog } from "../../logger/logger.js";
@@ -104,7 +105,14 @@ export const startNotificationMonitor = async () => {
}, 5 * 1000);
};
const createJob = (id: string, schedule: string, task: () => Promise<void>) => {
const createJob = async (
id: string,
schedule: string,
task: () => Promise<void>
) => {
const { data, error } = (await tryCatch(db.select().from(settings))) as any;
const timeZone = data.filter((n: any) => n.name === "timezone");
// Destroy existing job if it exists
if (runningCrons[id]) {
runningCrons[id].stop(); // Croner uses .stop() instead of .destroy()
@@ -114,7 +122,7 @@ const createJob = (id: string, schedule: string, task: () => Promise<void>) => {
runningCrons[id] = new Cron(
schedule,
{
timezone: "America/Chicago",
timezone: timeZone[0].timezone,
catch: true, // Prevents unhandled rejections
},
task