feat: add nestjs replacement, remove nestjs (#285)

* feat: add nestjs replacement, remove nestjs

* fix: format issues

* fix: dependency issues

* fix: dependency issues

* fix: format issue

* fix: wrong channel used for logging channel
This commit is contained in:
Meier Lukas
2024-04-04 18:31:40 +02:00
committed by GitHub
parent c82915c6dc
commit 1936596c04
38 changed files with 599 additions and 2197 deletions

View File

@@ -1,40 +1,13 @@
import { Redis } from "ioredis";
import superjson from "superjson";
import { createQueueChannel, createSubPubChannel } from "./lib/channel";
import { logger } from "@homarr/log";
const subscriber = new Redis();
const publisher = new Redis();
const lastDataClient = new Redis();
const createChannel = <TData>(name: string) => {
return {
subscribe: (callback: (data: TData) => void) => {
void lastDataClient.get(`last-${name}`).then((data) => {
if (data) {
callback(superjson.parse(data));
}
});
void subscriber.subscribe(name, (err) => {
if (!err) {
return;
}
logger.error(
`Error with channel '${name}': ${err.name} (${err.message})`,
);
});
subscriber.on("message", (channel, message) => {
if (channel !== name) return;
callback(superjson.parse(message));
});
},
publish: async (data: TData) => {
await lastDataClient.set(`last-${name}`, superjson.stringify(data));
await publisher.publish(name, superjson.stringify(data));
},
};
};
export const exampleChannel = createSubPubChannel<{ message: string }>(
"example",
);
export const queueChannel = createQueueChannel<{
name: string;
executionDate: Date;
data: unknown;
}>("common-queue");
export interface LoggerMessage {
message: string;
@@ -42,6 +15,4 @@ export interface LoggerMessage {
timestamp: string;
}
export const loggingChannel = createChannel<LoggerMessage>("logging");
export const exampleChannel = createChannel<{ message: string }>("example");
export const loggingChannel = createSubPubChannel<LoggerMessage>("logging");