Skip to content

Commit a7de417

Browse files
committed
feat: Add option to run in production without redis
Fixes #110
1 parent 659c24c commit a7de417

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ class PreAggregations {
372372
this.queryCache = queryCache;
373373
this.refreshErrors = {}; // TODO should be in redis
374374
this.tablesUsedInQuery = {}; // TODO should be in redis
375-
this.cacheDriver = process.env.NODE_ENV === 'production' || process.env.REDIS_URL ?
375+
this.cacheDriver = options.cacheAndQueueDriver === 'redis' ?
376376
new RedisCacheDriver() :
377377
new LocalCacheDriver();
378378
this.externalDriverFactory = options.externalDriverFactory;
@@ -416,7 +416,12 @@ class PreAggregations {
416416
new PreAggregationLoadCache(this.redisPrefix, this.driverFactory, this.queryCache, this)
417417
);
418418
return loader.refresh(newVersionEntry)(client);
419-
}, { concurrency: 1, logger: this.logger, ...this.options.queueOptions });
419+
}, {
420+
concurrency: 1,
421+
logger: this.logger,
422+
cacheAndQueueDriver: this.options.cacheAndQueueDriver,
423+
...this.options.queueOptions
424+
});
420425
}
421426
return this.queue;
422427
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class QueryCache {
1111
this.driverFactory = clientFactory;
1212
this.externalDriverFactory = options.externalDriverFactory;
1313
this.logger = logger;
14-
this.cacheDriver = process.env.NODE_ENV === 'production' || process.env.REDIS_URL ?
14+
this.cacheDriver = options.cacheAndQueueDriver === 'redis' ?
1515
new RedisCacheDriver() :
1616
new LocalCacheDriver();
1717
}
@@ -101,8 +101,11 @@ class QueryCache {
101101
this.queue = QueryCache.createQueue(
102102
`SQL_QUERY_${this.redisPrefix}`,
103103
this.driverFactory,
104-
(client, q) => client.query(q.query, q.values),
105-
{ logger: this.logger, ...this.options.queueOptions }
104+
(client, q) => client.query(q.query, q.values), {
105+
logger: this.logger,
106+
cacheAndQueueDriver: this.options.cacheAndQueueDriver,
107+
...this.options.queueOptions
108+
}
106109
);
107110
}
108111
return this.queue;
@@ -117,6 +120,7 @@ class QueryCache {
117120
{
118121
logger: this.logger,
119122
concurrency: 6,
123+
cacheAndQueueDriver: this.options.cacheAndQueueDriver,
120124
...this.options.externalQueueOptions
121125
}
122126
);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,24 @@ class QueryOrchestrator {
88
this.driverFactory = driverFactory;
99
this.logger = logger;
1010
const { externalDriverFactory } = options;
11+
const cacheAndQueueDriver = options.cacheAndQueueDriver || process.env.CUBEJS_CACHE_AND_QUEUE_DRIVER || (
12+
process.env.NODE_ENV === 'production' || process.env.REDIS_URL ? 'redis' : 'memory'
13+
);
14+
if (cacheAndQueueDriver !== 'redis' && cacheAndQueueDriver !== 'memory') {
15+
throw new Error(`Only 'redis' or 'memory' are supported for cacheAndQueueDriver option`);
16+
}
17+
1118
this.queryCache = new QueryCache(
1219
this.redisPrefix, this.driverFactory, this.logger, {
1320
externalDriverFactory,
21+
cacheAndQueueDriver,
1422
...options.queryCacheOptions,
1523
}
1624
);
1725
this.preAggregations = new PreAggregations(
1826
this.redisPrefix, this.driverFactory, this.logger, this.queryCache, {
1927
externalDriverFactory,
28+
cacheAndQueueDriver,
2029
...options.preAggregationsOptions
2130
}
2231
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class QueryQueue {
2525
heartBeatTimeout: this.heartBeatInterval * 4,
2626
createRedisClient: options.createRedisClient
2727
};
28-
this.queueDriver = process.env.NODE_ENV === 'production' || process.env.REDIS_URL || !!options.createRedisClient ?
28+
this.queueDriver = options.cacheAndQueueDriver === 'redis' ?
2929
new RedisQueueDriver(queueDriverOptions) :
3030
new LocalQueueDriver(queueDriverOptions);
3131
}

0 commit comments

Comments
 (0)