@@ -30,6 +30,26 @@ export interface QueryOrchestratorOptions {
3030 skipExternalCacheAndQueue ?: boolean ;
3131}
3232
33+ function detectQueueAndCacheDriver ( options : QueryOrchestratorOptions ) : CacheAndQueryDriverType {
34+ if ( options . cacheAndQueueDriver ) {
35+ return options . cacheAndQueueDriver ;
36+ }
37+
38+ if ( getEnv ( 'cacheAndQueueDriver' ) ) {
39+ return getEnv ( 'cacheAndQueueDriver' ) ;
40+ }
41+
42+ if ( getEnv ( 'redisUrl' ) || getEnv ( 'redisUseIORedis' ) ) {
43+ return 'redis' ;
44+ }
45+
46+ if ( getEnv ( 'nodeEnv' ) === 'production' ) {
47+ return 'cubestore' ;
48+ }
49+
50+ return 'memory' ;
51+ }
52+
3353export class QueryOrchestrator {
3454 protected readonly queryCache : QueryCache ;
3555
@@ -50,22 +70,19 @@ export class QueryOrchestrator {
5070 options : QueryOrchestratorOptions = { }
5171 ) {
5272 this . rollupOnlyMode = options . rollupOnlyMode ;
53-
54- const cacheAndQueueDriver = options . cacheAndQueueDriver || getEnv ( 'cacheAndQueueDriver' ) || (
55- ( getEnv ( 'nodeEnv' ) === 'production' || getEnv ( 'redisUrl' ) || getEnv ( 'redisUseIORedis' ) )
56- ? 'redis'
57- : 'memory'
58- ) ;
59- this . cacheAndQueueDriver = cacheAndQueueDriver ;
73+ const cacheAndQueueDriver = detectQueueAndCacheDriver ( options ) ;
6074
6175 if ( ! [ 'redis' , 'memory' , 'cubestore' ] . includes ( cacheAndQueueDriver ) ) {
62- throw new Error ( 'Only \'redis\', \'memory\' or \'cubestore\' are supported for cacheAndQueueDriver option' ) ;
76+ throw new Error (
77+ `Only 'cubestore', 'redis' or 'memory' are supported for cacheAndQueueDriver option, passed: ${ cacheAndQueueDriver } `
78+ ) ;
6379 }
6480
6581 const { externalDriverFactory, continueWaitTimeout, skipExternalCacheAndQueue } = options ;
6682
6783 const redisPool = cacheAndQueueDriver === 'redis' ? new RedisPool ( options . redisPoolOptions ) : undefined ;
6884 this . redisPool = redisPool ;
85+ this . cacheAndQueueDriver = cacheAndQueueDriver ;
6986
7087 const cubeStoreDriverFactory = cacheAndQueueDriver === 'cubestore' ? async ( ) => {
7188 if ( externalDriverFactory ) {
0 commit comments