import type { BaseTask, TaskResultType } from "../tasks/base"; import type { ValidResultType } from "../tasks/base-action"; import type { GraphResult } from "./results"; import { GraphResults } from "./results"; import type { GraphSolver } from "./solver"; export interface InternalNodeTypes { status: StatusTaskNode; process: ProcessTaskNode; } export interface NodeTypes extends InternalNodeTypes { request: RequestTaskNode; } export type NodeType = keyof NodeTypes; export interface TaskNodeParams { solver: GraphSolver; task: T; dependant?: TaskNode; statusOnly: boolean; } export declare abstract class TaskNode { abstract readonly executionType: NodeType; readonly type: string; startedAt?: Date; readonly task: T; readonly statusOnly: boolean; abstract readonly concurrencyLimit: number; abstract readonly concurrencyGroupKey: string; protected solver: GraphSolver; protected dependants: { [key: string]: TaskNode; }; protected result?: GraphResult; /** * When complete handler is called, we need to know if the run handler has been called (i.e. the process task node has been processed). * * The implementations of the TaskNode abstract class need to make that decision; The complete method will use this information to inform the result. */ protected abstract processed: boolean; constructor({ solver, task, statusOnly }: TaskNodeParams); abstract describe(): string; abstract getDependencies(): TaskNode[]; abstract execute(): Promise | null>; getKey(): string; addDependant(node: TaskNode): void; /** * Returns all dependencies that does not yet have a result, i.e. is not resolved. */ getRemainingDependencies(): TaskNode[]; /** * Get the result for the given dependency node. Returns undefined if result is not yet set. */ getDependencyResult(node: TaskNode): GraphResult> | undefined; /** * Returns all dependency results. */ getDependencyResults(): GraphResults; isComplete(): boolean; /** * Completes the node, setting its result and propagating it to each dependant node. * * If the node is aborted or an error is set, dependants are aborted. * * If the node was already completed, this is a no-op (may e.g. happen if the node has been completed * but a dependency fails and is aborting dependants). */ complete({ startedAt, error, result, aborted, abortedKeys }: CompleteTaskParams): GraphResult>; /** * Returns the task result if the task is completed. Returns undefined if result is not available. */ getStatus(): GraphResult | undefined; protected getNode(type: NT, task: BaseTask): TaskNode>; } export interface TaskRequestParams extends TaskNodeParams { batchId: string; statusOnly: boolean; completeHandler: CompleteHandler>; } export declare class RequestTaskNode extends TaskNode { readonly executionType: NodeType; readonly requestedAt: Date; readonly batchId: string; private readonly completeHandler; constructor(params: TaskRequestParams); get concurrencyLimit(): number; get concurrencyGroupKey(): keyof NodeTypes; get processed(): boolean; describe(): string; getKey(): string; getDependencies(): TaskNode[]; complete(params: CompleteTaskParams): GraphResult>; execute(): Promise; } export declare class ProcessTaskNode extends TaskNode { readonly executionType: NodeType; get concurrencyLimit(): number; /** * Tasks with different limits will be grouped in separate concurrency groups. * * E.g. if 50 build tasks have limit of 5, and 30 build tasks have limit of 10, then 15 build tasks will execute concurrently. */ get concurrencyGroupKey(): string; get processed(): boolean; describe(): string; private getStatusResult; getDependencies(): TaskNode>[]; execute(): Promise; } export declare class StatusTaskNode extends TaskNode { readonly executionType: NodeType; get concurrencyLimit(): number; get processed(): boolean; /** * Tasks with different limits will be grouped in separate concurrency groups. * * E.g. if 50 build tasks have limit of 5, and 30 build tasks have limit of 10, then 15 build tasks will execute concurrently. */ get concurrencyGroupKey(): string; describe(): string; getDependencies(): TaskNode>[]; execute(): Promise; } export declare function getNodeKey(task: BaseTask, type: NodeType): string; export type CompleteHandler = (result: GraphResult) => void; export interface CompleteTaskParams { startedAt: Date | null; error: Error | null; result: ValidResultType | null; aborted: boolean; abortedKeys?: Set; }