feat(notificaitons): fixed and corrections to get them working properly
This commit is contained in:
@@ -31,7 +31,10 @@ export const note: any = [
|
||||
timeType: "min",
|
||||
emails: "",
|
||||
active: false,
|
||||
notifiySettings: { prodID: 1, sentBlockingOrders: [1] },
|
||||
notifiySettings: {
|
||||
prodID: 1,
|
||||
sentBlockingOrders: [{ timeStamp: "0", blockingOrder: 1 }],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "productionCheck",
|
||||
@@ -72,8 +75,8 @@ export const note: any = [
|
||||
notifiySettings: {
|
||||
prodID: 1,
|
||||
start: 36,
|
||||
end: 720,
|
||||
releases: [1, 2, 3],
|
||||
end: 36,
|
||||
releases: [{ timeStamp: "0", releaseNumber: 1 }],
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -86,7 +89,7 @@ export const note: any = [
|
||||
notifiySettings: {
|
||||
prodID: 1,
|
||||
start: 36,
|
||||
end: 720,
|
||||
end: 36,
|
||||
releases: [1, 2, 3],
|
||||
},
|
||||
},
|
||||
@@ -98,7 +101,14 @@ export const notificationCreate = async () => {
|
||||
const notify = await db
|
||||
.insert(notifications)
|
||||
.values(note[i])
|
||||
.onConflictDoNothing();
|
||||
.onConflictDoUpdate({
|
||||
target: notifications.name,
|
||||
set: {
|
||||
name: note[i].name,
|
||||
description: note[i].description,
|
||||
//notifiySettings: note[i].notifiySettings,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
createLog(
|
||||
"error",
|
||||
@@ -110,4 +120,10 @@ export const notificationCreate = async () => {
|
||||
);
|
||||
}
|
||||
}
|
||||
createLog(
|
||||
"info",
|
||||
"lst",
|
||||
"nofity",
|
||||
"notifications were just added/updated due to server startup"
|
||||
);
|
||||
};
|
||||
|
||||
@@ -43,23 +43,43 @@ export const startNotificationMonitor = async () => {
|
||||
|
||||
if (
|
||||
!note.active ||
|
||||
note.emails === "" ||
|
||||
// note.emails === "" ||
|
||||
runningNotifications[note.name]
|
||||
) {
|
||||
//console.log(`Skipping ${note.name} hes already scheduled`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!runningNotifications[note.name] && note.active) {
|
||||
createLog(
|
||||
"info",
|
||||
"notify",
|
||||
"notify",
|
||||
`${note.name} Is active and not already running.`
|
||||
);
|
||||
}
|
||||
|
||||
let time = `*/30 * * * *`; // default to be every 30 min
|
||||
|
||||
if (note.timeType === "min") {
|
||||
console.log(`Creating the min mark here`);
|
||||
time = `*/${note.checkInterval} * * * *`;
|
||||
//console.log(`Creating the min mark here`);
|
||||
const totalMinutes = note.checkInterval;
|
||||
if (note.checkInterval > 60) {
|
||||
const hours = Math.floor(totalMinutes / 60); // 1 hour
|
||||
const minutes = totalMinutes % 60; // 45 minutes
|
||||
time = `*/${minutes} */${hours} * * *`;
|
||||
} else {
|
||||
time = `*/${note.checkInterval} * * * *`;
|
||||
}
|
||||
}
|
||||
|
||||
if (note.timeType === "hour") {
|
||||
console.log(`Creating the hour mark here`);
|
||||
time = `* */${note.checkInterval} * * *`;
|
||||
const totalHours = note.checkInterval;
|
||||
if (note.checkInterval > 60) {
|
||||
const days = Math.floor(totalHours / 24); // 1 hour
|
||||
const hours = totalHours % 24; // 45 minutes
|
||||
time = `* */${hours} */${days} * *`;
|
||||
} else {
|
||||
time = `* */${note.checkInterval} * * *`;
|
||||
}
|
||||
}
|
||||
|
||||
createJob(note.name, time, async () => {
|
||||
|
||||
Reference in New Issue
Block a user