Skip to content

Commit

Permalink
Merge pull request #1552 from betagouv/fix/redis-config-warnings
Browse files Browse the repository at this point in the history
fix Redis warnings
  • Loading branch information
nmrgt authored Nov 10, 2021
2 parents 2c51f8e + af36512 commit 57eb3e2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
12 changes: 9 additions & 3 deletions api/ilos/connection-redis/src/RedisConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class RedisConnection implements ConnectionInterface<RedisInterface> {

async down() {
if (this.connected) {
await this.getClient().disconnect();
this.getClient().disconnect();
this.connected = false;
}
}
Expand All @@ -32,16 +32,22 @@ export class RedisConnection implements ConnectionInterface<RedisInterface> {
}

protected buildClient(): RedisInterface {
const defaultConfig = {
maxRetriesPerRequest: null,
enableReadyCheck: false,
// lazyConnect: true,
};

if (this.config.connectionString) {
const { connectionString, ...other } = this.config;
return new Redis(connectionString, {
...defaultConfig,
...other,
// lazyConnect: true,
});
}
return new Redis({
...defaultConfig,
...this.config,
// lazyConnect: true,
});
}
}
14 changes: 7 additions & 7 deletions api/ilos/transport-redis/src/QueueTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface WorkerWithScheduler {
export class QueueTransport implements TransportInterface<WorkerWithScheduler[]> {
queues: WorkerWithScheduler[] = [];
kernel: KernelInterface;
connection: RedisConnection;
connections: RedisConnection[] = [];

constructor(kernel: KernelInterface) {
this.kernel = kernel;
Expand All @@ -33,11 +33,10 @@ export class QueueTransport implements TransportInterface<WorkerWithScheduler[]>
}

protected async getRedisConnection(connectionString: string): Promise<RedisInterface> {
if (!this.connection) {
this.connection = new RedisConnection({ connectionString });
await this.connection.up();
}
return this.connection.getClient();
const connection = new RedisConnection({ connectionString });
await connection.up();
this.connections.push(connection);
return connection.getClient();
}

protected getWorker(connection: RedisInterface, name: string, processor: Processor): Worker {
Expand Down Expand Up @@ -100,7 +99,8 @@ export class QueueTransport implements TransportInterface<WorkerWithScheduler[]>
promises.push(scheduler.close());
}
await Promise.all(promises);
await this.connection.down();
await Promise.all(this.connections.map((c: RedisConnection) => c.down()));
this.connections = [];
}

protected errorHandler(_error: Error, _job?: Job) {
Expand Down

0 comments on commit 57eb3e2

Please sign in to comment.