import { firestore } from "firebase-admin"; import { Slice } from "./common"; export interface WorkerShardingInfo { slice: Slice; hasData: boolean; overloaded: boolean; splits: string[]; } export interface ControllerData { workers: Slice[]; timestamp: number; } export declare enum ControllerStatus { WORKERS_RUNNING = 0, TOO_MANY_SHARDS = 1, SUCCESS = 2, FAILURE = 3 } /** * Controller is run every minute by Cloud Scheduler and monitors health of workers via their * metadata documents. If any worker is overloaded or average worker load is below * 1000 shards/minute workers will be rebalanced based on their reported stats. * * Additionally it'll try to aggregate up to 200 shards in-line to avoid starting dedicated * workers for low traffic workloads. */ export declare class ShardedCounterController { private controllerDocRef; private shardCollectionId; private workersRef; private db; constructor(controllerDocRef: firestore.DocumentReference, shardCollectionId: string); /** * Try aggregating up to 'limit' shards for a fixed amount of time. If workers * are running or there's too many shards, it won't run aggregations at all. */ aggregateContinuously(slice: Slice, limit: number, timeoutMillis: number): Promise; /** * Try aggregating up to 'limit' shards. If workers are running or there's too many * shards return with appropriate status code. */ aggregateOnce(slice: Slice, limit: number): Promise; /** * Reschedule workers based on stats in their metadata docs. */ rescheduleWorkers(): Promise; /** * Checks if current workers are imbalanced or overloaded. Returns true and new slices * if resharding is required. * @param currentWorkers Sharding info for workers based on their stats */ protected static balanceWorkers(currentWorkers: WorkerShardingInfo[]): [boolean, Slice[]]; protected static encodeWorkerKey(idx: number): string; } //# sourceMappingURL=controller.d.ts.map