import { QueueDriverConnectionInterface, QueryKey, QueryKeyHash, QueueId, QueryDef, AddToQueueQuery, AddToQueueOptions, AddToQueueResponse, QueryKeysTuple, GetActiveAndToProcessResponse, QueryStageStateResponse, RetrieveForProcessingSuccess, QueueDriverOptions, QueuePriority } from '@cubejs-backend/base-driver'; import { LocalQueueDriver } from './LocalQueueDriver'; /** * `Pending -> Active`, then removed outright by an ack or a cancel. `Active` is the only lock * there is: retrieveForProcessing sets it atomically. */ export declare enum LocalQueueItemStatus { Pending = "pending", Active = "active" } export interface QueryDefObject { queueId: QueueId; queryHandler: string; query: any; queryKey: QueryKey; stageQueryKey: string; priority: number; requestId: string; addedToQueueTime: number; } export interface LocalQueueItem { /** * Starts at 1, never 0: callers fall back to a key lookup on a falsy queueId. */ id: number; key: QueryKeyHash; status: LocalQueueItemStatus; priority: number; created: number; heartbeat: number | null; /** * Absolute deadline in ms, not a duration. Pushed forward by every addToQueue of the same * key, so a query somebody is still waiting for doesn't get orphaned behind a long backlog. */ orphaned: number; payload: QueryDefObject; /** * Written only by optimisticQueryUpdate, kept out of the payload so that a concurrent * update cannot mutate the def other connections are holding. */ extra: Record | null; } export interface PromiseWithResolve extends Promise { resolve?: (value: T) => void; resolved?: boolean; } /** * Queue items indexed by key and by id, both indexes are only ever updated together. */ export declare class LocalQueueItems { /** * A Map because insertion order matches id order, which is the order active items are * reported in. A plain object would reorder them. */ protected readonly byKey: Map; protected readonly byId: Map; protected idSequence: number; nextId(): number; getByKey(key: QueryKeyHash): LocalQueueItem | null; getById(id: number): LocalQueueItem | null; has(key: QueryKeyHash): boolean; add(item: LocalQueueItem): void; remove(item: LocalQueueItem): void; values(): IterableIterator; } export declare class LocalQueueDriverConnectionState { readonly resultPromises: Record; readonly items: LocalQueueItems; } export declare class LocalQueueDriverConnection implements QueueDriverConnectionInterface { private readonly redisQueuePrefix; private readonly continueWaitTimeout; private readonly orphanedTimeout; private readonly heartBeatTimeout; private readonly concurrency; private readonly driver; private readonly state; constructor(driver: LocalQueueDriver, state: LocalQueueDriverConnectionState, options: QueueDriverOptions); /** * There is deliberately no key fallback once an id is supplied: a stale id has to miss, * otherwise an in-flight query would never notice that it was cancelled and re-added * under a new id. */ protected resolveItem(queryKeyHash: QueryKeyHash, queueId?: QueueId | null): LocalQueueItem | null; protected mergeDef(item: LocalQueueItem): QueryDef; /** * FIFO within a priority band. The id breaks ties between items added in the same millisecond. */ protected sortedItems(): LocalQueueItem[]; protected pendingItems(): LocalQueueItem[]; /** * Deliberately not priority sorted, unlike pendingItems: active items are reported in id order. */ protected activeItems(): LocalQueueItem[]; protected countPending(): number; protected asTuple(items: LocalQueueItem[]): QueryKeysTuple[]; getQueriesToCancel(): Promise; getActiveAndToProcess(): Promise; getResultPromise(resultListKey: string): PromiseWithResolve; getResultBlocking(queryKeyHash: QueryKeyHash, _queueId?: QueueId): Promise; getResult(queryKey: QueryKey, _externalId?: string): Promise; addToQueue(queryKey: QueryKey, queryHandler: string, query: AddToQueueQuery, priority: QueuePriority, options: AddToQueueOptions): Promise; getToProcessQueries(): Promise; getActiveQueries(): Promise; getQueryAndRemove(queryKeyHash: QueryKeyHash, queueId?: QueueId | null): Promise<[QueryDef]>; cancelQuery(queryKey: QueryKey, queueId?: QueueId | null): Promise; setResultAndRemoveQuery(queryKeyHash: QueryKeyHash, executionResult: any, queueId: QueueId): Promise; protected isOrphaned(item: LocalQueueItem, now: number): boolean; /** * options.orphanedTimeout is in seconds and overrides the driver level one. */ protected orphanedDeadline(now: number, options: AddToQueueOptions): number; protected isStalled(item: LocalQueueItem, now: number): boolean; getOrphanedQueries(): Promise; getStalledQueries(): Promise; getQueryStageState(onlyKeys: boolean): Promise; getQueryDef(queryKeyHash: QueryKeyHash, queueId?: QueueId | null): Promise; updateHeartBeat(queryKeyHash: QueryKeyHash, queueId?: QueueId | null): Promise; retrieveForProcessing(queryKeyHash: QueryKeyHash, queueId: QueueId): Promise; optimisticQueryUpdate(queryKeyHash: QueryKeyHash, toUpdate: any, queueId: QueueId): Promise; release(): void; queryRedisKey(queryKey: QueryKey, suffix: string): string; resultListKey(queryKey: QueryKey | QueryKeyHash): string; redisHash(queryKey: QueryKey): QueryKeyHash; } //# sourceMappingURL=LocalQueueDriverConnection.d.ts.map