This commit is contained in:
Benjamin Toby
2025-02-16 17:12:40 +01:00
parent e9761cc971
commit e95f4d1087
628 changed files with 3091 additions and 1073 deletions
@@ -0,0 +1,88 @@
import { _n } from "@/client-exports";
import getQueue from "@/package-shared/functions/backend/queues/get-queue";
import updateQueue from "@/package-shared/functions/backend/queues/update-queue";
import { DSQL_DATASQUIREL_PROCESS_QUEUE } from "@/package-shared/types/dsql";
import debugLog from "@/package-shared/utils/logging/debug-log";
function debugLogFn(log: any, label?: string) {
debugLog({ log, addTime: true, label, title: __filename.split("/").pop() });
}
export default async function cronHandleQueue() {
const INTERVAL = 5000;
while (true) {
await (async () => {
const lastQueueItemRes = (await getQueue({
query: {
query: {
error: {
value: "0",
},
running: {
value: "0",
},
success: {
value: "0",
},
},
order: {
field: "id",
strategy: "ASC",
},
limit: 1,
},
})) as DSQL_DATASQUIREL_PROCESS_QUEUE[] | undefined;
const lastQueueItem = lastQueueItemRes?.[0];
if (!lastQueueItem) return;
debugLogFn(lastQueueItem.title, "Running Queue");
await updateQueue({
queueId: _n(lastQueueItem.id),
queue: {
running: 1,
},
});
try {
switch (lastQueueItem.job_type) {
/**
* # Dummy Queue
*/
case "dummy":
await Bun.sleep(20000);
break;
/**
* # Unhandled
*/
default:
return;
}
} catch (error: any) {
debugLogFn(error.message, "ERROR");
await updateQueue({
queueId: _n(lastQueueItem.id),
queue: {
running: 0,
error: 1,
error_message: String(error.message),
},
});
return;
}
await updateQueue({
queueId: _n(lastQueueItem.id),
queue: {
success: 1,
},
});
})();
await Bun.sleep(INTERVAL);
}
}
@@ -0,0 +1,55 @@
import createDbFromSchema from "@/package-shared/shell/createDbFromSchema";
import grabDirNames from "@/package-shared/utils/backend/names/grab-dir-names";
import debugLog from "@/package-shared/utils/logging/debug-log";
import dbSchemaToType from "@/utils/backend/db-schema-to-type";
import fs from "fs";
function debugLogFn(log: any, label?: string) {
debugLog({ log, addTime: true, label, title: "watchMainDbSchemaJSONFile" });
}
let syncing = 0;
let timeout: any;
const DEBOUNCE = 500;
export default function watchMainDbSchemaJSONFile() {
if (process.env.NODE_ENV?.match(/prod/)) return;
if (process.env.DSQL_HOST_ENV?.match(/prod/)) return;
const { mainShemaJSONFilePath, mainDbTypeDefFile } = grabDirNames();
fs.watch(mainShemaJSONFilePath, (curr) => {
if (syncing == 1) return;
if (curr !== "change") return;
clearTimeout(timeout);
debugLogFn("Main Schema JSON File Changed!");
syncing = 1;
timeout = setTimeout(() => {
const definitions = dbSchemaToType();
fs.writeFileSync(
mainDbTypeDefFile,
definitions?.join("\n\n") || "",
"utf-8"
);
createDbFromSchema({})
.then((res) => {
debugLogFn(res, "res");
})
.catch((err) => {
debugLogFn(err, "res");
})
.finally(() => {
setTimeout(() => {
debugLogFn("Main Rebuilt Successfully!");
syncing = 0;
}, 1000);
});
}, DEBOUNCE);
});
}