Skip to content

Commit

Permalink
feat: Add option to run in production without redis
Browse files Browse the repository at this point in the history
Fixes #110
  • Loading branch information
paveltiunov committed Jun 7, 2019
1 parent 659c24c commit a7de417
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ class PreAggregations {
this.queryCache = queryCache;
this.refreshErrors = {}; // TODO should be in redis
this.tablesUsedInQuery = {}; // TODO should be in redis
this.cacheDriver = process.env.NODE_ENV === 'production' || process.env.REDIS_URL ?
this.cacheDriver = options.cacheAndQueueDriver === 'redis' ?
new RedisCacheDriver() :
new LocalCacheDriver();
this.externalDriverFactory = options.externalDriverFactory;
Expand Down Expand Up @@ -416,7 +416,12 @@ class PreAggregations {
new PreAggregationLoadCache(this.redisPrefix, this.driverFactory, this.queryCache, this)
);
return loader.refresh(newVersionEntry)(client);
}, { concurrency: 1, logger: this.logger, ...this.options.queueOptions });
}, {
concurrency: 1,
logger: this.logger,
cacheAndQueueDriver: this.options.cacheAndQueueDriver,
...this.options.queueOptions
});
}
return this.queue;
}
Expand Down
10 changes: 7 additions & 3 deletions packages/cubejs-query-orchestrator/orchestrator/QueryCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class QueryCache {
this.driverFactory = clientFactory;
this.externalDriverFactory = options.externalDriverFactory;
this.logger = logger;
this.cacheDriver = process.env.NODE_ENV === 'production' || process.env.REDIS_URL ?
this.cacheDriver = options.cacheAndQueueDriver === 'redis' ?
new RedisCacheDriver() :
new LocalCacheDriver();
}
Expand Down Expand Up @@ -101,8 +101,11 @@ class QueryCache {
this.queue = QueryCache.createQueue(
`SQL_QUERY_${this.redisPrefix}`,
this.driverFactory,
(client, q) => client.query(q.query, q.values),
{ logger: this.logger, ...this.options.queueOptions }
(client, q) => client.query(q.query, q.values), {
logger: this.logger,
cacheAndQueueDriver: this.options.cacheAndQueueDriver,
...this.options.queueOptions
}
);
}
return this.queue;
Expand All @@ -117,6 +120,7 @@ class QueryCache {
{
logger: this.logger,
concurrency: 6,
cacheAndQueueDriver: this.options.cacheAndQueueDriver,
...this.options.externalQueueOptions
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ class QueryOrchestrator {
this.driverFactory = driverFactory;
this.logger = logger;
const { externalDriverFactory } = options;
const cacheAndQueueDriver = options.cacheAndQueueDriver || process.env.CUBEJS_CACHE_AND_QUEUE_DRIVER || (
process.env.NODE_ENV === 'production' || process.env.REDIS_URL ? 'redis' : 'memory'
);
if (cacheAndQueueDriver !== 'redis' && cacheAndQueueDriver !== 'memory') {
throw new Error(`Only 'redis' or 'memory' are supported for cacheAndQueueDriver option`);
}

this.queryCache = new QueryCache(
this.redisPrefix, this.driverFactory, this.logger, {
externalDriverFactory,
cacheAndQueueDriver,
...options.queryCacheOptions,
}
);
this.preAggregations = new PreAggregations(
this.redisPrefix, this.driverFactory, this.logger, this.queryCache, {
externalDriverFactory,
cacheAndQueueDriver,
...options.preAggregationsOptions
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class QueryQueue {
heartBeatTimeout: this.heartBeatInterval * 4,
createRedisClient: options.createRedisClient
};
this.queueDriver = process.env.NODE_ENV === 'production' || process.env.REDIS_URL || !!options.createRedisClient ?
this.queueDriver = options.cacheAndQueueDriver === 'redis' ?
new RedisQueueDriver(queueDriverOptions) :
new LocalQueueDriver(queueDriverOptions);
}
Expand Down

0 comments on commit a7de417

Please sign in to comment.