Skip to content

Commit ff20167

Browse files
authored
feat: Use options pattern in constructor (#468) Thanks to @jcw-!
1 parent 2484eb3 commit ff20167

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

packages/cubejs-query-orchestrator/orchestrator/PreAggregations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ class PreAggregations {
523523
this.logger = logger;
524524
this.queryCache = queryCache;
525525
this.cacheDriver = options.cacheAndQueueDriver === 'redis' ?
526-
new RedisCacheDriver(options.redisPool) :
526+
new RedisCacheDriver({ pool: options.redisPool }) :
527527
new LocalCacheDriver();
528528
this.externalDriverFactory = options.externalDriverFactory;
529529
}

packages/cubejs-query-orchestrator/orchestrator/QueryCache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class QueryCache {
1212
this.externalDriverFactory = options.externalDriverFactory;
1313
this.logger = logger;
1414
this.cacheDriver = options.cacheAndQueueDriver === 'redis' ?
15-
new RedisCacheDriver(options.redisPool) :
15+
new RedisCacheDriver({ pool: options.redisPool }) :
1616
new LocalCacheDriver();
1717
}
1818

packages/cubejs-query-orchestrator/orchestrator/RedisCacheDriver.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
class RedisCacheDriver {
2-
constructor(pool) {
2+
constructor({ pool }) {
33
this.redisPool = pool;
44
}
55

66
async getClient() {
7-
return await this.redisPool.getClient();
7+
return this.redisPool.getClient();
88
}
99

1010
async get(key) {

packages/cubejs-query-orchestrator/orchestrator/RedisPool.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ const genericPool = require('generic-pool');
22
const createRedisClient = require('./RedisFactory');
33

44
class RedisPool {
5-
constructor(poolMin, poolMax, createClient, destroyClient) {
5+
constructor(options) {
6+
options = options || {};
67
const defaultMin = process.env.CUBEJS_REDIS_POOL_MIN ? parseInt(process.env.CUBEJS_REDIS_POOL_MIN, 10) : 2;
78
const defaultMax = process.env.CUBEJS_REDIS_POOL_MAX ? parseInt(process.env.CUBEJS_REDIS_POOL_MAX, 10) : 1000;
8-
const min = (typeof poolMin !== 'undefined') ? poolMin : defaultMin;
9-
const max = (typeof poolMax !== 'undefined') ? poolMax : defaultMax;
10-
const create = createClient || (() => createRedisClient(process.env.REDIS_URL));
11-
const destroy = destroyClient || (client => client.end(true));
9+
const min = (typeof options.poolMin !== 'undefined') ? options.poolMin : defaultMin;
10+
const max = (typeof options.poolMax !== 'undefined') ? options.poolMax : defaultMax;
11+
const create = options.createClient || (() => createRedisClient(process.env.REDIS_URL));
12+
const destroy = options.destroyClient || (client => client.end(true));
1213
const opts = {
1314
min,
1415
max,

packages/cubejs-query-orchestrator/test/QueryQueue.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,4 @@ const QueryQueueTest = (name, options) => {
141141

142142
QueryQueueTest('Local');
143143
QueryQueueTest('RedisPool', { cacheAndQueueDriver: 'redis', redisPool: new RedisPool() });
144-
QueryQueueTest('RedisNoPool', { cacheAndQueueDriver: 'redis', redisPool: new RedisPool(0, 0) });
144+
QueryQueueTest('RedisNoPool', { cacheAndQueueDriver: 'redis', redisPool: new RedisPool({ poolMin: 0, poolMax: 0 }) });

0 commit comments

Comments
 (0)