forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix redis connection (twentyhq#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
- Loading branch information
Showing
6 changed files
with
58 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/twenty-server/src/engine/core-modules/redis-client/redis-client.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Global, Module } from '@nestjs/common'; | ||
|
||
import { EnvironmentModule } from 'src/engine/core-modules/environment/environment.module'; | ||
import { RedisClientService } from 'src/engine/core-modules/redis-client/redis-client.service'; | ||
|
||
@Global() | ||
@Module({ | ||
imports: [EnvironmentModule], | ||
providers: [RedisClientService], | ||
exports: [RedisClientService], | ||
}) | ||
export class RedisClientModule {} |
33 changes: 33 additions & 0 deletions
33
packages/twenty-server/src/engine/core-modules/redis-client/redis-client.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Injectable, OnModuleDestroy } from '@nestjs/common'; | ||
|
||
import IORedis from 'ioredis'; | ||
|
||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service'; | ||
|
||
@Injectable() | ||
export class RedisClientService implements OnModuleDestroy { | ||
private redisClient: IORedis | null = null; | ||
|
||
constructor(private readonly environmentService: EnvironmentService) {} | ||
|
||
getClient() { | ||
if (!this.redisClient) { | ||
const redisUrl = this.environmentService.get('REDIS_URL'); | ||
|
||
if (!redisUrl) { | ||
throw new Error('REDIS_URL must be defined'); | ||
} | ||
|
||
this.redisClient = new IORedis(redisUrl); | ||
} | ||
|
||
return this.redisClient; | ||
} | ||
|
||
async onModuleDestroy() { | ||
if (this.redisClient) { | ||
await this.redisClient.quit(); | ||
this.redisClient = null; | ||
} | ||
} | ||
} |