@@ -167,95 +167,6 @@ export class QueryQueue {
167167 return stream ;
168168 }
169169
170- /**
171- * Depends on the `queryHandler` value either runs `executeQueryInQueue`
172- * or `executeStreamInQueue` method.
173- *
174- * @param {string } queryHandler For the regular query is eq to 'query'.
175- * @param {* } queryKey
176- * @param {* } query
177- * @param {number= } priority
178- * @param {*= } options
179- * @returns {* }
180- *
181- * @throw {ContinueWaitError }
182- */
183- async executeInQueue (
184- queryHandler ,
185- queryKey ,
186- query ,
187- priority ,
188- options ,
189- ) {
190- return this . executeQueryInQueue (
191- queryHandler ,
192- queryKey ,
193- query ,
194- priority ,
195- options ,
196- ) ;
197- }
198-
199- /**
200- * Push persistent query to the queue and call `QueryQueue.reconcileQueue()` method.
201- *
202- * @param {string } queryHandler
203- * @param {* } queryKey
204- * @param {* } query
205- * @param {number= } priority
206- * @param {*= } options
207- * @returns {Promise<void> }
208- */
209- async executeStreamInQueue (
210- queryHandler ,
211- queryKey ,
212- query ,
213- priority ,
214- options ,
215- ) {
216- options = options || { } ;
217- const queueConnection = await this . queueDriver . createConnection ( ) ;
218- try {
219- priority = priority || 0 ;
220- if ( ! ( priority >= - 10000 && priority <= 10000 ) ) {
221- throw new Error (
222- 'Priority should be between -10000 and 10000'
223- ) ;
224- }
225- const time = new Date ( ) . getTime ( ) ;
226- const keyScore = time + ( 10000 - priority ) * 1E14 ;
227-
228- options . orphanedTimeout = query . orphanedTimeout ;
229- const orphanedTimeout = 'orphanedTimeout' in query
230- ? query . orphanedTimeout
231- : this . orphanedTimeout ;
232- const orphanedTime = time + ( orphanedTimeout * 1000 ) ;
233-
234- const [ added , _b , _c , queueSize , addedToQueueTime ] = await queueConnection . addToQueue (
235- keyScore , queryKey , orphanedTime , queryHandler , query , priority , options
236- ) ;
237- if ( added > 0 ) {
238- this . logger ( 'Added to queue (persistent)' , {
239- priority,
240- queueSize,
241- queryKey,
242- queuePrefix : this . redisQueuePrefix ,
243- requestId : options . requestId ,
244- metadata : query . metadata ,
245- preAggregationId : query . preAggregation ?. preAggregationId ,
246- newVersionEntry : query . newVersionEntry ,
247- forceBuild : query . forceBuild ,
248- preAggregation : query . preAggregation ,
249- addedToQueueTime,
250- persistent : queryKey . persistent ,
251- } ) ;
252- }
253- this . reconcileQueue ( ) ;
254- } finally {
255- this . queueDriver . release ( queueConnection ) ;
256- }
257- }
258-
259170 /**
260171 * Push query to the queue and call `QueryQueue.reconcileQueue()` method if
261172 * `options.skipQueue` is set to `false`, execute query skipping queue
@@ -270,7 +181,7 @@ export class QueryQueue {
270181 *
271182 * @throw {ContinueWaitError }
272183 */
273- async executeQueryInQueue (
184+ async executeInQueue (
274185 queryHandler ,
275186 queryKey ,
276187 query ,
@@ -334,7 +245,7 @@ export class QueryQueue {
334245 const orphanedTimeout = 'orphanedTimeout' in query ? query . orphanedTimeout : this . orphanedTimeout ;
335246 const orphanedTime = time + ( orphanedTimeout * 1000 ) ;
336247
337- const [ added , _b , _c , queueSize , addedToQueueTime ] = await queueConnection . addToQueue (
248+ const [ added , queueId , queueSize , addedToQueueTime ] = await queueConnection . addToQueue (
338249 keyScore , queryKey , orphanedTime , queryHandler , query , priority , options
339250 ) ;
340251
@@ -400,7 +311,7 @@ export class QueryQueue {
400311 } else {
401312 // Result here won't be fetched for a jobed build query (initialized by
402313 // the /cubejs-system/v1/pre-aggregations/jobs endpoint).
403- result = ! query . isJob && await queueConnection . getResultBlocking ( queryKey ) ;
314+ result = ! query . isJob && await queueConnection . getResultBlocking ( queryKeyHash , queueId ) ;
404315 }
405316
406317 // We don't want to throw the ContinueWaitError for a jobed build query.
@@ -763,8 +674,8 @@ export class QueryQueue {
763674 }
764675
765676 /**
766- * Processing query specified by the `queryKey`. This method incapsulate most
767- * of the logic related with the queues updates, heartbeating , etc.
677+ * Processing query specified by the `queryKey`. This method encapsulate most
678+ * of the logic related with the queues updates, heartbeat , etc.
768679 *
769680 * @param {QueryKeyHash } queryKeyHashed
770681 * @return {Promise<{ result: undefined | Object, error: string | undefined }> }
@@ -773,17 +684,18 @@ export class QueryQueue {
773684 const queueConnection = await this . queueDriver . createConnection ( ) ;
774685
775686 let insertedCount ;
776- let _removedCount ;
687+ let queueId ;
777688 let activeKeys ;
778689 let queueSize ;
779690 let query ;
780691 let processingLockAcquired ;
692+
781693 try {
782694 const processingId = await queueConnection . getNextProcessingId ( ) ;
783695 const retrieveResult = await queueConnection . retrieveForProcessing ( queryKeyHashed , processingId ) ;
784696
785697 if ( retrieveResult ) {
786- [ insertedCount /** todo(ovr): Remove */ , _removedCount /** todo(ovr): Remove */ , activeKeys , queueSize , query , processingLockAcquired ] = retrieveResult ;
698+ [ insertedCount , queueId , activeKeys , queueSize , query , processingLockAcquired ] = retrieveResult ;
787699 }
788700
789701 const activated = activeKeys && activeKeys . indexOf ( queryKeyHashed ) !== - 1 ;
@@ -808,7 +720,7 @@ export class QueryQueue {
808720 preAggregation : query . query ?. preAggregation ,
809721 addedToQueueTime : query . addedToQueueTime ,
810722 } ) ;
811- await queueConnection . optimisticQueryUpdate ( queryKeyHashed , { startQueryTime } , processingId ) ;
723+ await queueConnection . optimisticQueryUpdate ( queryKeyHashed , { startQueryTime } , processingId , queueId ) ;
812724
813725 const heartBeatTimer = setInterval (
814726 ( ) => queueConnection . updateHeartBeat ( queryKeyHashed ) ,
@@ -840,7 +752,7 @@ export class QueryQueue {
840752 query . query ,
841753 async ( cancelHandler ) => {
842754 try {
843- return queueConnection . optimisticQueryUpdate ( queryKeyHashed , { cancelHandler } , processingId ) ;
755+ return queueConnection . optimisticQueryUpdate ( queryKeyHashed , { cancelHandler } , processingId , queueId ) ;
844756 } catch ( e ) {
845757 this . logger ( 'Error while query update' , {
846758 queryKey : query . queryKey ,
@@ -916,7 +828,7 @@ export class QueryQueue {
916828
917829 clearInterval ( heartBeatTimer ) ;
918830
919- if ( ! ( await queueConnection . setResultAndRemoveQuery ( queryKeyHashed , executionResult , processingId ) ) ) {
831+ if ( ! ( await queueConnection . setResultAndRemoveQuery ( queryKeyHashed , executionResult , processingId , queueId ) ) ) {
920832 this . logger ( 'Orphaned execution result' , {
921833 processingId,
922834 warn : 'Result for query was not set due to processing lock wasn\'t acquired' ,
@@ -937,7 +849,7 @@ export class QueryQueue {
937849 // if (query?.queryHandler === 'stream') {
938850 // const [active] = await queueConnection.getQueryStageState(true);
939851 // if (active && active.length > 0) {
940- // await Promise.race(active.map(keyHash => queueConnection.getResultBlockingByHash (keyHash)));
852+ // await Promise.race(active.map(keyHash => queueConnection.getResultBlocking (keyHash)));
941853 // await this.reconcileQueue();
942854 // }
943855 // }
0 commit comments