nx
Version:
180 lines (179 loc) • 7.78 kB
TypeScript
import { NxJsonConfiguration } from '../config/nx-json';
import { ProjectGraph } from '../config/project-graph';
import { Task, TaskGraph } from '../config/task-graph';
import { DaemonClient } from '../daemon/client/client';
import { TaskHasher } from '../hasher/task-hasher';
import { NxArgs } from '../utils/command-line-utils';
import { DefaultTasksRunnerOptions } from './default-tasks-runner';
import { TaskResult } from './life-cycle';
import { RunningTask } from './running-tasks/running-task';
import { TaskStatus } from './tasks-runner';
import { Batch } from './tasks-schedule';
import { SharedRunningTask } from './running-tasks/shared-running-task';
export declare class TaskOrchestrator {
private readonly hasher;
private readonly initiatingProject;
private readonly initiatingTasks;
private readonly projectGraph;
private readonly taskGraph;
private readonly nxJson;
private readonly options;
private readonly bail;
private readonly daemon;
private readonly outputStyle;
private readonly taskGraphForHashing;
private taskDetails;
private cache;
private readonly tuiEnabled;
private readonly projects;
private forkedProcessTaskRunner;
private runningTasksService;
private tasksSchedule;
private batchEnv;
private reverseTaskDeps;
private initializingTaskIds;
private processedTasks;
private completedTasks;
private waitingForTasks;
private pendingDiscreteWorkers;
private groups;
private continuousTasksStarted;
private bailed;
private resolveStopPromise;
private stopRequested;
private runningContinuousTasks;
private runningRunCommandsTasks;
private runningDiscreteTasks;
private discreteTaskExitHandled;
private continuousTaskExitHandled;
private cleanupPromise;
constructor(hasher: TaskHasher, initiatingProject: string | undefined, initiatingTasks: Task[], projectGraph: ProjectGraph, taskGraph: TaskGraph, nxJson: NxJsonConfiguration, options: NxArgs & DefaultTasksRunnerOptions, bail: boolean, daemon: DaemonClient, outputStyle: string, taskGraphForHashing?: TaskGraph);
init(): Promise<void>;
run(): Promise<{
[k: string]: TaskStatus;
}>;
nextBatch(): Batch;
/**
* Coordinator loop. All batch operations (hashing, cache resolution)
* happen on this single thread — no races. Cache misses are dispatched
* as fire-and-forget workers. Workers signal completion via
* scheduleNextTasksAndReleaseThreads which wakes all waiting loops.
*
* Safety: the dispatch phase (step 5) is fully synchronous — no
* worker can run during it. So all tasks picked up by nextTask()
* are guaranteed to be in processedTasks from step 1.
*/
private executeCoordinatorLoop;
private executeContinuousTaskLoop;
private processTask;
processAllScheduledTasks(): void;
private applyCachedResults;
/**
* Batch cache lookup + filter to successful entries. Handles both
* local (one rarray SQL call) and remote (parallel HTTP retrievals)
* inside DbCache.getBatch.
*/
private fetchCacheHits;
/**
* For each confirmed cache hit: decide whether to copy outputs from
* the cache (skipping if the on-disk outputs already match the
* recorded hash), copy in parallel, derive the task status, print
* terminal output, and return the assembled results.
*/
private finalizeCacheHits;
/**
* Coordinator wrapper around {@link resolveCachedTasks}: peeks at
* scheduledTasks (without removing anything from the schedule),
* filters to cacheable hashed discrete candidates, and delegates the
* cache fetch + lifecycle to the public method. Returns true if any
* tasks were resolved.
*
* The coordinator relies on this running unconditionally (when cache
* is enabled): tasks dispatched in step 5 via runTaskDirectly skip
* their own cache lookup on the assumption that this has already
* confirmed them as misses. Don't add length-based bails.
*/
private resolveCachedTasksBulk;
/**
* Hash all batch tasks and resolve cache hits topologically.
*
* Walks the task graph level by level. Every task gets a preliminary hash
* (so startTasks always has a valid hash for Cloud). Tasks with depsOutputs
* whose deps weren't cached are ineligible for cache lookup but still
* receive a preliminary hash — they'll be re-hashed after execution.
*/
private applyBatchCachedResults;
private hashBatchTasks;
applyFromCacheOrRunBatch(doNotSkipCache: boolean, batch: Batch, groupId: number): Promise<TaskResult[]>;
private runBatch;
/**
* Bulk-resolve cache hits for a set of tasks: fetch cached entries,
* copy outputs as needed, fire lifecycle, and return the TaskResults
* for the hits. Tasks that aren't in the cache (or aren't cacheable)
* are silently omitted from the return value — callers are responsible
* for running those via {@link runTaskDirectly}.
*
* Fires scheduleTask lifecycle for hits that haven't been through
* processAllScheduledTasks yet. That's a coordinator gap-filler and
* a no-op for callers that pre-process the schedule.
*
* The caller provides `groupId` — cache hits share one slot since they
* don't actually compete for parallelism.
*/
resolveCachedTasks(doNotSkipCache: boolean, tasks: Task[], groupId: number): Promise<TaskResult[]>;
/**
* Fire a discrete-task worker and track it in pendingDiscreteWorkers until
* it settles. Uses runTaskDirectly (not applyFromCacheOrRun*) because
* resolveCachedTasksBulk already confirmed this task is a cache miss —
* another lookup would re-query the DB and (for Nx Cloud users) repeat
* the remote HTTP retrieval.
*/
private dispatchDiscreteWorker;
/**
* Route a worker rejection (e.g. remote cache errors) through the normal
* failure path instead of letting it become an unhandled promise. Guard
* against double-finalize: completeTasks() populates `completedTasks`,
* so a rejection arriving after postRunSteps has already finalized the
* task must not run postRunSteps again.
*/
private handleDiscreteWorkerFailure;
/**
* Spawn and wait on a task's child process, unconditionally — no cache
* lookup. Callers must have already confirmed the task is a cache miss
* (or disabled caching entirely).
*/
runTaskDirectly(doNotSkipCache: boolean, task: Task, groupId: number): Promise<TaskResult>;
private runTask;
private runTaskInForkedProcess;
startContinuousTask(task: Task, groupId: number): Promise<RunningTask | SharedRunningTask>;
private preRunSteps;
private postRunSteps;
private scheduleNextTasksAndReleaseThreads;
private complete;
/**
* Unified task completion handler for a set of tasks.
* - Calls endTasks() lifecycle hook (non-skipped only)
* - Marks complete in scheduler
* - Sets completedTasks
* - Updates TUI status
* - Skip dependent tasks
*/
private completeTasks;
private pipeOutputCapture;
private shouldCacheTaskResult;
private closeGroup;
private openGroup;
private shouldCopyOutputsFromCacheBatch;
private recordOutputsHashBatch;
private handleContinuousTaskExit;
private completeContinuousTask;
private cleanup;
private performCleanup;
private setupSignalHandlers;
private cleanUpUnneededContinuousTasks;
}
export declare function getThreadPoolSize(options: NxArgs & DefaultTasksRunnerOptions, taskGraph: TaskGraph): {
discrete: number;
continuous: number;
total: number;
};