Fix redis connection (#7956)

## Context
bull-mq connection was not working as intended, the connection parameter
was ignored and was falling back to localhost.
This PR should fix the issue by instantiating a IORedis client following
bullmq documentation https://docs.bullmq.io/guide/connections
I also changed cache-storage module to use IORedis client as well to be
more consistent even though it was not necessary there. We could move
that instantiation to a factory class in the future.

## Test
start server + worker with correct port and wrong port with
cache-storage-type memory/redis and queue-type sync/bull-mq
This commit is contained in:
Weiko
2024-10-22 16:40:18 +02:00
committed by GitHub
parent 18cfe79b80
commit 02c34d547f
6 changed files with 58 additions and 23 deletions

View File

@ -1,5 +1,3 @@
import { ConnectionOptions } from 'tls';
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
import {
BullMQDriverFactoryOptions,
@ -8,6 +6,7 @@ import {
PgBossDriverFactoryOptions,
SyncDriverFactoryOptions,
} from 'src/engine/core-modules/message-queue/interfaces';
import { RedisClientService } from 'src/engine/core-modules/redis-client/redis-client.service';
/**
* MessageQueue Module factory
@ -16,6 +15,7 @@ import {
*/
export const messageQueueModuleFactory = async (
environmentService: EnvironmentService,
redisClientService: RedisClientService,
): Promise<MessageQueueModuleOptions> => {
const driverType = environmentService.get('MESSAGE_QUEUE_TYPE');
@ -37,18 +37,10 @@ export const messageQueueModuleFactory = async (
} satisfies PgBossDriverFactoryOptions;
}
case MessageQueueDriverType.BullMQ: {
const connectionString = environmentService.get('REDIS_URL');
if (!connectionString) {
throw new Error(
`${MessageQueueDriverType.BullMQ} message queue requires REDIS_URL to be defined, check your .env file`,
);
}
return {
type: MessageQueueDriverType.BullMQ,
options: {
connection: connectionString as ConnectionOptions,
connection: redisClientService.getClient(),
},
} satisfies BullMQDriverFactoryOptions;
}