refactor(datamart): more work on the new query system

This commit is contained in:
2026-01-13 17:07:46 -06:00
parent 00b4fb1a0a
commit 74677d12c4
3 changed files with 67 additions and 1 deletions

View File

@@ -84,6 +84,7 @@ export const runDatamartQuery = async (data: Data) => {
notify: false,
});
}
return returnFunc({
success: true,
level: "info",

View File

@@ -2,9 +2,10 @@
* If we are running in client mode we want to periodically check the SERVER_NAME for new/updates queries
* this will be on a cronner job, we will check 2 times a day for new data, we will also have a route we can trigger to check this manually incase we have
* queries we make for one plant but will eventually go to all plants.
* in client mode we will not be able to add, update, or delete
* in client mode we will not be able to add, update, or delete, or push updates
*
* if we are running on server mode we will provide all queries.
* when pushing to another server we will allow all or just a single server by plant token.
* allow for new queries to be added
* allow for queries to be updated by id
* table will be
@@ -19,4 +20,41 @@
* add_user
* upd_date
* upd_user
*
* if we are running in localhost or dev or just someone running the server on there computer but using localhost we will allow to push to the main server the SERVER_NAME in the env should point to the main server
* that way when we check if we are in production we will know.
* the node env must also be set non production in order to push to the main server.
* we will also be able to do all the same as the server mode but the push here will just go to the main server.
*/
// doing the client stuff first
// ┌──────────────── (optional) second (0 - 59)
// │ ┌────────────── minute (0 - 59)
// │ │ ┌──────────── hour (0 - 23)
// │ │ │ ┌────────── day of month (1 - 31)
// │ │ │ │ ┌──────── month (1 - 12, JAN-DEC)
// │ │ │ │ │ ┌────── day of week (0 - 6, SUN-Mon)
// │ │ │ │ │ │ (0 to 6 are Sunday to Saturday; 7 is Sunday, the same as 0)
// │ │ │ │ │ │
// * * * * * *
if (process.env.NODE_ENV?.trim() === "production") {
// setup cronner
let cronTime = "* 5 * * * *";
if (process.env.QUERY_TIME_TYPE === "m") {
// will run this cron ever x
cronTime = `* ${process.env.QUERY_CHECK} * * * *`;
}
if (process.env.QUERY_TIME_TYPE === "h") {
// will run this cron ever x
cronTime = `* * ${process.env.QUERY_CHECK} * * * `;
}
if (process.env.QUERY_TIME_TYPE === "d") {
// will run this cron ever x
cronTime = `* * * * * ${process.env.QUERY_CHECK}`;
}
console.info(cronTime);
}

View File

@@ -1,4 +1,5 @@
import build from "pino-abstract-transport";
import { db } from "../db/db.controller.js";
import { logs } from "../db/schema/logs.schema.js";
import { tryCatch } from "../utils/trycatch.utils.js";
@@ -41,3 +42,29 @@ export default async function () {
console.error("Error inserting log into database:", err);
}
}
// export const dbStream = {
// write: async (logString: string) => {
// try {
// const obj = JSON.parse(logString);
// const levelName = pinoLogLevels[obj.level] || "unknown";
// const res = await tryCatch(
// db.insert(logs).values({
// level: levelName,
// module: obj?.module?.toLowerCase(),
// subModule: obj?.subModule?.toLowerCase(),
// hostname: obj?.hostname?.toLowerCase(),
// message: obj.msg,
// stack: obj?.stack,
// }),
// );
// if (res.error) {
// console.error("DB log error:", res.error);
// }
// } catch (err) {
// console.error("Error parsing/inserting log:", err);
// }
// },
// };