From a05aa099d0f321b9511cbad62aba2edc748f6089 Mon Sep 17 00:00:00 2001 From: Leonardo <leomilho@gmail.com> Date: Mon, 27 Jan 2025 12:53:08 +0100 Subject: [PATCH] chore: make redis connector a global var making it inline with other services --- src/index.ts | 6 ++---- src/readers/queryService.ts | 9 ++------- src/variables.ts | 3 +++ 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index 21b5520..40397da 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,5 @@ -import { RedisConnector } from 'ts-common/redis'; import { RabbitMqBroker } from 'ts-common/rabbitMq'; -import { REDIS_PASSWORD, REDIS_HOST, REDIS_PORT, RABBIT_USER, RABBIT_PASSWORD, RABBIT_PORT, RABBIT_HOST, rabbitMq } from './variables'; +import { rabbitMq, redis } from './variables'; import { log } from './logger'; import { queryServiceReader } from './readers/queryService'; import { insightProcessor } from './readers/insightProcessor'; @@ -21,11 +20,10 @@ async function main() { log.info('Connected to RabbitMQ!'); log.info('Connecting to Redis...'); - const redis = new RedisConnector(REDIS_PASSWORD, REDIS_HOST, REDIS_PORT); await redis.connect(); log.info('Connected to Redis!'); - queryServiceReader(frontendPublisher, mlPublisher, redis, 'neo4j'); + queryServiceReader(frontendPublisher, mlPublisher, 'neo4j'); insightProcessor(); // TODO: other query services for other databases diff --git a/src/readers/queryService.ts b/src/readers/queryService.ts index e6ae06e..5fa9526 100644 --- a/src/readers/queryService.ts +++ b/src/readers/queryService.ts @@ -1,6 +1,6 @@ import { type DbConnection, type QueryRequest } from 'ts-common'; -import { rabbitMq, ums, type QueryExecutionTypes } from '../variables'; +import { rabbitMq, redis, ums, type QueryExecutionTypes } from '../variables'; import { log } from '../logger'; import { QueryPublisher } from '../utils/queryPublisher'; import { query2Cypher } from '../utils/cypher/converter'; @@ -32,12 +32,7 @@ export const queryService = async (db: DbConnection, query: string): Promise<Gra } }; -export const queryServiceReader = async ( - frontendPublisher: RabbitMqBroker, - mlPublisher: RabbitMqBroker, - redis: RedisConnector, - type: QueryExecutionTypes, -) => { +export const queryServiceReader = async (frontendPublisher: RabbitMqBroker, mlPublisher: RabbitMqBroker, type: QueryExecutionTypes) => { if (type == null) { log.error('Unsupported query execution type:', type); throw new Error('Unsupported query execution type'); diff --git a/src/variables.ts b/src/variables.ts index ee8ba87..18c889b 100644 --- a/src/variables.ts +++ b/src/variables.ts @@ -1,6 +1,7 @@ import { UMSApi } from 'ts-common'; import { RabbitMqConnection } from 'ts-common/rabbitMq'; import nodemailer from 'nodemailer'; +import { RedisConnector } from 'ts-common/redis'; export type QueryExecutionTypes = 'neo4j'; @@ -20,6 +21,8 @@ export const REDIS_PORT = parseInt(Bun.env.REDIS_PORT || '6379'); export const REDIS_PASSWORD = Bun.env.REDIS_PASSWORD || 'DevOnlyPass'; export const REDIS_SCHEMA_CACHE_DURATION = Bun.env.REDIS_SCHEMA_CACHE_DURATION || '60m'; +export const redis = new RedisConnector(REDIS_PASSWORD, REDIS_HOST, REDIS_PORT); + export const ums = new UMSApi(USER_MANAGEMENT_SERVICE_API); export const rabbitMq = new RabbitMqConnection({ protocol: 'amqp', -- GitLab