feat(eom): added in historical inv data split accordingly

This commit is contained in:
2025-05-28 17:01:22 -05:00
parent 25cfee58d0
commit 96deca15f0
16 changed files with 6385 additions and 36 deletions

View File

@@ -1,11 +1,12 @@
import { db } from "../../../../database/dbclient.js";
import { notifications } from "../../../../database/schema/notifications.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import type { JobInfo } from "../../../types/JobInfo.js";
import { createLog } from "../../logger/logger.js";
import { Cron } from "croner";
// Store active timeouts by notification ID
export let runningNotifications: Record<string, Cron> = {};
export let runningCrons: Record<string, Cron> = {};
export const startNotificationMonitor = async () => {
// if restarted or crashed we need to make sure the running notifications is cleared
@@ -29,7 +30,7 @@ export const startNotificationMonitor = async () => {
for (const note of notes) {
//if we get deactivated remove it.
if (runningNotifications[note.name] && !note.active) {
if (runningCrons[note.name] && !note.active) {
createLog(
"info",
"notify",
@@ -44,12 +45,12 @@ export const startNotificationMonitor = async () => {
if (
!note.active ||
// note.emails === "" ||
runningNotifications[note.name]
runningCrons[note.name]
) {
continue;
}
if (!runningNotifications[note.name] && note.active) {
if (!runningCrons[note.name] && note.active) {
createLog(
"info",
"notify",
@@ -105,12 +106,12 @@ export const startNotificationMonitor = async () => {
const createJob = (id: string, schedule: string, task: () => Promise<void>) => {
// Destroy existing job if it exists
if (runningNotifications[id]) {
runningNotifications[id].stop(); // Croner uses .stop() instead of .destroy()
if (runningCrons[id]) {
runningCrons[id].stop(); // Croner uses .stop() instead of .destroy()
}
// Create new job with Croner
runningNotifications[id] = new Cron(
runningCrons[id] = new Cron(
schedule,
{
timezone: "America/Chicago",
@@ -125,15 +126,8 @@ const createJob = (id: string, schedule: string, task: () => Promise<void>) => {
// });
};
interface JobInfo {
id: string;
schedule: string;
nextRun: Date | null;
isRunning: boolean;
}
export const getAllJobs = (): JobInfo[] => {
return Object.entries(runningNotifications).map(([id, job]) => ({
return Object.entries(runningCrons).map(([id, job]) => ({
id,
schedule: job.getPattern() || "invalid",
nextRun: job.nextRun() || null,
@@ -143,15 +137,15 @@ export const getAllJobs = (): JobInfo[] => {
};
const removeNotification = (id: any) => {
if (runningNotifications[id]) {
runningNotifications[id].stop();
delete runningNotifications[id];
if (runningCrons[id]) {
runningCrons[id].stop();
delete runningCrons[id];
}
};
export const stopAllJobs = () => {
Object.values(runningNotifications).forEach((job: any) => job.stop());
runningNotifications = {}; // Clear the object
Object.values(runningCrons).forEach((job: any) => job.stop());
runningCrons = {}; // Clear the object
};
/*