import type { DataBus } from '@ms-cloudpack/data-bus'; import type { Task } from '../types/Task.js'; import type { TaskStats } from '../types/TaskStats.js'; /** * TaskRunner tracks the status of tasks, manages concurrency, allows reusing task results, * and sends notifications about task status to the data bus (currently just used for `start`). * * NOTE: To enable data bus notifications, you must call `connectToBus()`. * `createApiContext` does this with the `taskRunner` passed in. * (`createPartialApiContext` does not create or connect a data bus.) */ export declare class TaskRunner { private _bus; private readonly _queue; /** Stats about task errors/warnings, only updated if a bus is connected */ private _taskIssues; /** * Tasks that are currently either running or waiting. (Note that `PQeueue`'s definition of * "pending" is slightly different: it only counts tasks that are currently running.) */ private readonly _pendingTasks; /** Tasks that have completed */ private readonly _completedTasks; /** * Task IDs where a re-run was requested while the task was running. * We let the current task finish, and then re-run it. */ private readonly _requiresRerun; /** All previously-seen tasks (regardless of state) */ private readonly _allTasks; constructor(); /** * Get current task stats. Public for testing. * @internal */ get _taskStats(): Readonly; /** * Connects the TaskRunner to the data bus. Tasks will still run without this, but they won't * send any notifications to a client (which only matters if a client is listening, e.g. * the browser while running `start`). */ connectToBus(bus: DataBus): void; /** * Enqueue a task and return its result promise. * * If a task with the same `id` was already added, it returns either the previous result * (if completed) or the promise (if pending). Pass `options.rerun` to force re-running. * * (Note that any re-runs will use the *original* task function, not the new one. * If something has changed that requires a new task function, you should incorporate this * into the `id`.) */ add(task: Task, options?: { rerun?: boolean; priority?: number; }): Promise; /** * Dispose in-memory resources of all tasks and clear the TaskRunner's state. */ dispose(): void; /** * Clear the result of a specific task (could involve deleting files from disk) and remove * it from the TaskRunner's task records. */ clearResult(id: string): Promise; /** * Clear the results of all tasks (might include deleting files on disk) and clear the * TaskRunner's task records. * * (To only dispose in-memory resources, use `dispose()`.) */ clearAllResults(): Promise; /** * Pauses the TaskRunner (for testing). * @internal */ _pause(): void; /** * Starts or resumes the TaskRunner (for testing). * @internal */ _start(): void; /** Remove any records of previous issues with this task from the totals */ private _removeTaskIssues; /** * Internal method to report the start of a task to the bus. */ private _reportStart; /** * Internal method to report the end of a task to the bus. */ private _reportEnd; /** Get the task list from the data bus, and find the task's index. */ private _findFromTaskList; /** * Publish tasks and/or stats to the data bus. */ private _publishUpdates; } //# sourceMappingURL=TaskRunner.d.ts.map