import type { Logger } from 'pino'; import { IPollingTaskOptions, IPollingTaskState, ITaskController } from '../types/public.js'; /** * TaskController manages the full lifecycle of a single polling task. * It handles scheduling, execution with retries, timeouts, backoff logic, * and all lifecycle callbacks. * * IMP-6: Extracted from manager.ts into its own module. */ export declare class TaskController implements ITaskController { id: string; priority: number; name: string | null; fn: Array<(signal?: AbortSignal) => unknown | Promise>; interval: number; onData?: (data: unknown[]) => void; onError?: (error: Error, fnIndex: number, retryCount: number) => void; onStart?: () => void; onStop?: () => void; onFinish?: (success: boolean, results: unknown[]) => void; onBeforeEach?: () => void; onRetry?: (error: Error, fnIndex: number, retryCount: number) => void; shouldRun?: () => boolean; onSuccess?: (result: unknown) => void; onFailure?: (error: Error) => void; maxRetries: number; backoffDelay: number; taskTimeout: number; stopped: boolean; paused: boolean; executionInProgress: boolean; logger: Logger; private _isEnqueued; /** Whether the task is currently sitting in the manager's execution queue. */ get isEnqueued(): boolean; set isEnqueued(value: boolean); private timerId; private _abortController; /** * Callback the TaskController calls to enqueue itself into the manager queue. * Set by the PollingManager after construction. */ enqueueFn: (task: TaskController) => void; /** * Callback the TaskController calls to remove itself from the manager queue. * Set by the PollingManager after construction. */ dequeueFn: (taskId: string) => void; constructor(options: IPollingTaskOptions, logger: Logger); /** * Starts the task. * BUG-1 fix: Direct call, no setTimeout wrapper needed. */ start(): void; /** * Completely stops the task. * RISK-2 fix: Reset isEnqueued and remove from queue. * RISK-7 fix: Abort any in-flight sleep/timeout. */ stop(): void; /** * Pauses the task temporarily. * RISK-2 fix: Reset isEnqueued, remove from queue, and clear pending timer * so the timer doesn't re-enqueue the task while paused. */ pause(): void; /** * Resumes a previously paused task. */ resume(): void; private _scheduleNextRun; /** * Executes the task's functions with full retry logic, timeouts, and callbacks. * BUG-2 fix: Uses AbortController for real cancellation. * BUG-3 fix: overallSuccess uses && (all must succeed). * BUG-4 fix: onError called before onFailure. * RISK-7 fix: _sleep is interruptible. */ execute(): Promise; isRunning(): boolean; isPaused(): boolean; setInterval(ms: number): void; getState(): IPollingTaskState; /** * Returns a promise that resolves when the current execution finishes. * Used by RISK-6 (updateTask) to wait for graceful completion. */ waitForCompletion(timeoutMs?: number): Promise; private _logSpecificError; private _interruptibleSleep; /** * BUG-2 fix: Timeout with AbortController. * If the timeout fires before the promise settles, the AbortController * signal is aborted, giving the underlying operation a chance to cancel. */ private _withTimeoutAndAbort; /** Abort the current execution cycle's AbortController. */ private _abort; }