UNPKG

@mdf.js/tasks

Version:

MMS - API Core - Tasks

76 lines 2.65 kB
/** * Copyright 2024 Mytra Control S.L. All rights reserved. * * Use of this source code is governed by an MIT-style license that can be found in the LICENSE file * or at https://opensource.org/licenses/MIT. */ import { Health } from '@mdf.js/core'; import { Crash, Multi } from '@mdf.js/crash'; import EventEmitter from 'events'; import { Limiter } from '../Limiter'; import { MetaData } from '../Tasks'; import { MetricsDefinitions, PollingManagerOptions } from './types'; export declare interface PollingExecutor { /** Emitted on every error */ on(event: 'error', listener: (error: Crash | Multi) => void): this; /** Emitted on every state change */ on(event: 'status', listener: (status: Health.Status) => void): this; /** Emitted when a task has ended */ on(event: 'done', listener: (uuid: string, result: any, meta: MetaData, error?: Crash | Multi) => void): this; } /** Polling manager */ export declare class PollingExecutor extends EventEmitter { private readonly options; private readonly limiter; private readonly metrics; /** Debug logger for development and deep troubleshooting */ private readonly logger; /** Scan timer */ private scanTimer; /** Polling period in ms */ private readonly pollingPeriod; /** Polling manager stats */ private readonly manager; /** Cycle timer */ private cycleTimer; /** * Create a polling manager * @param options - Polling manager options * @param limiter - Rate limiter * @param metrics - Metrics registry */ constructor(options: PollingManagerOptions, limiter: Limiter, metrics: MetricsDefinitions); /** Include all the task entries in the limiter */ private readonly performScan; /** Get the next scan time */ private getNextScan; /** * Event handler for the end of a cycle event * @param check - Health check */ private readonly onEndCycle; /** * Event handler for error events * @param error - Error event */ private readonly onError; /** * Event handler for done events * @param uuid - Task UUID * @param result - Task result * @param meta - Task metadata * @param error - Task error */ private readonly onDone; /** Attach the event listeners */ private attachListeners; /** Detach the event listeners */ private detachListeners; /** Start the polling manager */ start(): void; /** Stop the polling manager */ stop(): void; /** Return the stats of the polling manager */ get check(): Health.Check; } //# sourceMappingURL=PollingExecutor.d.ts.map