@rushstack/operation-graph 0.1.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -49,8 +49,10 @@ export declare interface IExecuteOperationContext extends Omit<IOperationRunnerC
49
49
  afterExecute(operation: Operation, state: IOperationState): void;
50
50
  /**
51
51
  * Function used to schedule the concurrency-limited execution of an operation.
52
+ *
53
+ * Will return OperationStatus.Aborted if execution is aborted before the task executes.
52
54
  */
53
- queueWork<T>(workFn: () => Promise<T>, priority: number): Promise<T>;
55
+ queueWork(workFn: () => Promise<OperationStatus>, priority: number): Promise<OperationStatus>;
54
56
  /**
55
57
  * A callback to the overarching orchestrator to request that the operation be invoked again.
56
58
  * Used in watch mode to signal that inputs have changed.
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.37.0"
8
+ "packageVersion": "7.37.1"
9
9
  }
10
10
  ]
11
11
  }
@@ -40,8 +40,10 @@ export interface IExecuteOperationContext extends Omit<IOperationRunnerContext,
40
40
  afterExecute(operation: Operation, state: IOperationState): void;
41
41
  /**
42
42
  * Function used to schedule the concurrency-limited execution of an operation.
43
+ *
44
+ * Will return OperationStatus.Aborted if execution is aborted before the task executes.
43
45
  */
44
- queueWork<T>(workFn: () => Promise<T>, priority: number): Promise<T>;
46
+ queueWork(workFn: () => Promise<OperationStatus>, priority: number): Promise<OperationStatus>;
45
47
  /**
46
48
  * A callback to the overarching orchestrator to request that the operation be invoked again.
47
49
  * Used in watch mode to signal that inputs have changed.
@@ -1 +1 @@
1
- {"version":3,"file":"Operation.d.ts","sourceRoot":"","sources":["../src/Operation.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,KAAK,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAG7E,OAAO,KAAK,EACV,gBAAgB,EAChB,uBAAuB,EACvB,eAAe,EACf,gBAAgB,EACjB,MAAM,oBAAoB,CAA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nE;;;OAGG;IACH,OAAO,CAAC,WAAW,CAAiB;gBAEjB,OAAO,CAAC,EAAE,iBAAiB;IAOvC,aAAa,CAAC,UAAU,EAAE,SAAS,GAAG,IAAI;IAK1C,gBAAgB,CAAC,UAAU,EAAE,SAAS,GAAG,IAAI;IAK7C,KAAK,IAAI,IAAI;IAepB;;OAEG;IACU,aAAa,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,eAAe,CAAC;YAazE,kBAAkB;CA0HjC"}
package/lib/Operation.js CHANGED
@@ -167,7 +167,8 @@ class Operation {
167
167
  }
168
168
  : undefined
169
169
  };
170
- await queueWork(async () => {
170
+ // eslint-disable-next-line require-atomic-updates
171
+ state.status = await queueWork(async () => {
171
172
  // Redundant variable to satisfy require-atomic-updates
172
173
  const innerState = state;
173
174
  if (abortSignal.aborted) {
@@ -208,6 +209,7 @@ class Operation {
208
209
  }
209
210
  state.stopwatch.stop();
210
211
  context.afterExecute(this, state);
212
+ return state.status;
211
213
  }, /* priority */ this.criticalPathLength ?? 0);
212
214
  return state.status;
213
215
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Operation.js","sourceRoot":"","sources":["../src/Operation.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,oEAA6E;AAE7E,2CAAwC;AAQxC,uDAAoD;AA8DpD;;;;;;;;GAQG;AACH,MAAa,SAAS;IAyFpB,YAAmB,OAA2B;QAxF9C;;WAEG;QACa,iBAAY,GAAmB,IAAI,GAAG,EAAa,CAAC;QACpE;;WAEG;QACa,cAAS,GAAmB,IAAI,GAAG,EAAa,CAAC;QAUjE;;;WAGG;QACI,WAAM,GAAiC,SAAS,CAAC;QAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA4BG;QACI,uBAAkB,GAAuB,SAAS,CAAC;QAe1D;;WAEG;QACI,cAAS,GAAgC,SAAS,CAAC;QAE1D;;WAEG;QACI,UAAK,GAAgC,SAAS,CAAC;QAEtD;;WAEG;Q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GAAG,iCAAe,CAAC,SAAS,CAAC;YAC9C,0DAA0D;YAC1D,UAAU,CAAC,UAAU,GAAG,IAAI,CAAC;YAE7B,OAAO,IAAI,CAAC,WAAW,EAAE;gBACvB,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;gBACzB,IAAI;oBACF,mEAAmE;oBACnE,UAAU,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,iCAAe,CAAC,IAAI,CAAC;iBAC7F;gBAAC,OAAO,KAAK,EAAE;oBACd,UAAU,CAAC,MAAM,GAAG,iCAAe,CAAC,OAAO,CAAC;oBAC5C,UAAU,CAAC,KAAK,GAAG,KAAuB,CAAC;iBAC5C;gBAED,8FAA8F;gBAC9F,6FAA6F;gBAC7F,sBAAsB;gBAEtB,6FAA6F;gBAC7F,gGAAgG;gBAChG,qGAAqG;gBACrG,0FAA0F;gBAE1F,IAAI,IAAI,CAAC,WAAW,EAAE;oBACpB,IAAI,WAAW,CAAC,OAAO,EAAE;wBACvB,UAAU,CAAC,MAAM,GAAG,iCAAe,CAAC,OAAO,CAAC;wBAC5C,MAAM;qBACP;yBAAM;wBACL,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,uCAAuC,CAAC,CAAC;qBACrE;iBACF;aACF;YAED,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;YACvB,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACpC,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC,kBAAkB,IAAI,CAAC,CAAC,CAAC;QAEhD,OAAO,KAAK,CAAC,MAAM,CAAC;IACtB,CAAC;CACF;AAhQD,8BAgQC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { InternalError, type ITerminal } from '@rushstack/node-core-library';\n\nimport { Stopwatch } from './Stopwatch';\nimport type {\n IOperationRunner,\n IOperationRunnerContext,\n IOperationState,\n IOperationStates\n} from './IOperationRunner';\nimport type { OperationError } from './OperationError';\nimport { OperationStatus } from './OperationStatus';\n\n/**\n * Options for constructing a new Operation.\n * @beta\n */\nexport interface IOperationOptions {\n /**\n * The name of this operation, for logging.\n */\n name?: string | undefined;\n\n /**\n * The group that this operation belongs to. Will be used for logging and duration tracking.\n */\n groupName?: string | undefined;\n\n /**\n * When the scheduler is ready to process this `Operation`, the `runner` implements the actual work of\n * running the operation.\n */\n runner?: IOperationRunner | undefined;\n\n /**\n * The weight used by the scheduler to determine order of execution.\n */\n weight?: number | undefined;\n}\n\n/**\n * Information provided to `executeAsync` by the `OperationExecutionManager`.\n *\n * @beta\n */\nexport interface IExecuteOperationContext extends Omit<IOperationRunnerContext, 'isFirstRun' | 'requestRun'> {\n /**\n * Function to invoke before execution of an operation, for logging.\n */\n beforeExecute(operation: Operation, state: IOperationState): void;\n\n /**\n * Function to invoke after execution of an operation, for logging.\n */\n afterExecute(operation: Operation, state: IOperationState): void;\n\n /**\n * Function used to schedule the concurrency-limited execution of an operation.\n */\n queueWork<T>(workFn: () => Promise<T>, priority: number): Promise<T>;\n\n /**\n * A callback to the overarching orchestrator to request that the operation be invoked again.\n * Used in watch mode to signal that inputs have changed.\n */\n requestRun?: (requestor?: string) => void;\n\n /**\n * Terminal to write output to.\n */\n terminal: ITerminal;\n}\n\n/**\n * The `Operation` class is a node in the dependency graph of work that needs to be scheduled by the\n * `OperationExecutionManager`. Each `Operation` has a `runner` member of type `IOperationRunner`, whose\n * implementation manages the actual process of running a single operation.\n *\n * The graph of `Operation` instances will be cloned into a separate execution graph after processing.\n *\n * @beta\n */\nexport class Operation implements IOperationStates {\n /**\n * A set of all dependencies which must be executed before this operation is complete.\n */\n public readonly dependencies: Set<Operation> = new Set<Operation>();\n /**\n * A set of all operations that wait for this operation.\n */\n public readonly consumers: Set<Operation> = new Set<Operation>();\n /**\n * If specified, the name of a grouping to which this Operation belongs, for logging start and end times.\n */\n public readonly groupName: string | undefined;\n /**\n * The name of this operation, for logging.\n */\n public readonly name: string | undefined;\n\n /**\n * When the scheduler is ready to process this `Operation`, the `runner` implements the actual work of\n * running the operation.\n */\n public runner: IOperationRunner | undefined = undefined;\n\n /**\n * This number represents how far away this Operation is from the furthest \"root\" operation (i.e.\n * an operation with no consumers). This helps us to calculate the critical path (i.e. the\n * longest chain of projects which must be executed in order, thereby limiting execution speed\n * of the entire operation tree.\n *\n * This number is calculated via a memoized depth-first search, and when choosing the next\n * operation to execute, the operation with the highest criticalPathLength is chosen.\n *\n * Example:\n * (0) A\n * \\\\\n * (1) B C (0) (applications)\n * \\\\ /|\\\\\n * \\\\ / | \\\\\n * (2) D | X (1) (utilities)\n * | / \\\\\n * |/ \\\\\n * (2) Y Z (2) (other utilities)\n *\n * All roots (A & C) have a criticalPathLength of 0.\n * B has a score of 1, since A depends on it.\n * D has a score of 2, since we look at the longest chain (e.g D-\\>B-\\>A is longer than D-\\>C)\n * X has a score of 1, since the only package which depends on it is A\n * Z has a score of 2, since only X depends on it, and X has a score of 1\n * Y has a score of 2, since the chain Y-\\>X-\\>C is longer than Y-\\>C\n *\n * The algorithm is implemented in AsyncOperationQueue.ts as calculateCriticalPathLength()\n */\n public criticalPathLength: number | undefined = undefined;\n\n /**\n * The weight for this operation. This scalar is the contribution of this operation to the\n * `criticalPathLength` calculation above. Modify to indicate the following:\n * - `weight` === 1: indicates that this operation has an average duration\n * - `weight` &gt; 1: indicates that this operation takes longer than average and so the scheduler\n * should try to favor starting it over other, shorter operations. An example might be an operation that\n * bundles an entire application and runs whole-program optimization.\n * - `weight` &lt; 1: indicates that this operation takes less time than average and so the scheduler\n * should favor other, longer operations over it. An example might be an operation to unpack a cached\n * output, or an operation using NullOperationRunner, which might use a value of 0.\n */\n public weight: number;\n\n /**\n * The state of this operation the previous time a manager was invoked.\n */\n public lastState: IOperationState | undefined = undefined;\n\n /**\n * The current state of this operation\n */\n public state: IOperationState | undefined = undefined;\n\n /**\n * A cached execution promise for the current OperationExecutionManager invocation of this operation.\n */\n private _promise: Promise<OperationStatus> | undefined = undefined;\n\n /**\n * If true, then a run of this operation is currently wanted.\n * This is used to track state from the `requestRun` callback passed to the runner.\n */\n private _runPending: boolean = true;\n\n public constructor(options?: IOperationOptions) {\n this.groupName = options?.groupName;\n this.runner = options?.runner;\n this.weight = options?.weight || 1;\n this.name = options?.name;\n }\n\n public addDependency(dependency: Operation): void {\n this.dependencies.add(dependency);\n dependency.consumers.add(this);\n }\n\n public deleteDependency(dependency: Operation): void {\n this.dependencies.delete(dependency);\n dependency.consumers.delete(this);\n }\n\n public reset(): void {\n // Reset operation state\n this.lastState = this.state;\n\n this.state = {\n status: this.dependencies.size > 0 ? OperationStatus.Waiting : OperationStatus.Ready,\n hasBeenRun: this.lastState?.hasBeenRun ?? false,\n error: undefined,\n stopwatch: new Stopwatch()\n };\n\n this._promise = undefined;\n this._runPending = true;\n }\n\n /**\n * @internal\n */\n public async _executeAsync(context: IExecuteOperationContext): Promise<OperationStatus> {\n const { state } = this;\n if (!state) {\n throw new Error(`Operation state has not been initialized.`);\n }\n\n if (!this._promise) {\n this._promise = this._executeInnerAsync(context, state);\n }\n\n return this._promise;\n }\n\n private async _executeInnerAsync(\n context: IExecuteOperationContext,\n rawState: IOperationState\n ): Promise<OperationStatus> {\n const state: IOperationState = rawState;\n const { runner } = this;\n\n const dependencyResults: PromiseSettledResult<OperationStatus>[] = await Promise.allSettled(\n Array.from(this.dependencies, (dependency: Operation) => dependency._executeAsync(context))\n );\n\n const { abortSignal, requestRun, queueWork } = context;\n\n if (abortSignal.aborted) {\n state.status = OperationStatus.Aborted;\n return state.status;\n }\n\n for (const result of dependencyResults) {\n if (\n result.status === 'rejected' ||\n result.value === OperationStatus.Blocked ||\n result.value === OperationStatus.Failure\n ) {\n state.status = OperationStatus.Blocked;\n return state.status;\n }\n }\n\n state.status = OperationStatus.Ready;\n\n const innerContext: IOperationRunnerContext = {\n abortSignal,\n isFirstRun: !state.hasBeenRun,\n requestRun: requestRun\n ? () => {\n switch (this.state?.status) {\n case OperationStatus.Waiting:\n case OperationStatus.Ready:\n case OperationStatus.Executing:\n // If current status has not yet resolved to a fixed value,\n // re-executing this operation does not require a full rerun\n // of the operation graph. Simply mark that a run is requested.\n\n // This variable is on the Operation instead of the\n // containing closure to deal with scenarios in which\n // the runner hangs on to an old copy of the callback.\n this._runPending = true;\n return;\n\n case OperationStatus.Blocked:\n case OperationStatus.Aborted:\n case OperationStatus.Failure:\n case OperationStatus.NoOp:\n case OperationStatus.Success:\n // The requestRun callback is assumed to remain constant\n // throughout the lifetime of the process, so it is safe\n // to capture here.\n return requestRun(this.name);\n default:\n // This line is here to enforce exhaustiveness\n const currentStatus: undefined = this.state?.status;\n throw new InternalError(`Unexpected status: ${currentStatus}`);\n }\n }\n : undefined\n };\n\n await queueWork(async () => {\n // Redundant variable to satisfy require-atomic-updates\n const innerState: IOperationState = state;\n\n if (abortSignal.aborted) {\n innerState.status = OperationStatus.Aborted;\n return innerState.status;\n }\n\n context.beforeExecute(this, innerState);\n\n innerState.stopwatch.start();\n innerState.status = OperationStatus.Executing;\n // Mark that the operation has been started at least once.\n innerState.hasBeenRun = true;\n\n while (this._runPending) {\n this._runPending = false;\n try {\n // We don't support aborting in the middle of a runner's execution.\n innerState.status = runner ? await runner.executeAsync(innerContext) : OperationStatus.NoOp;\n } catch (error) {\n innerState.status = OperationStatus.Failure;\n innerState.error = error as OperationError;\n }\n\n // Since runner.executeAsync is async, a change could have occurred that requires re-execution\n // This operation is still active, so can re-execute immediately, rather than forcing a whole\n // new execution pass.\n\n // As currently written, this does mean that if a job is scheduled with higher priority while\n // this operation is still executing, it will still wait for this retry. This may not be desired\n // and if it becomes a problem, the retry loop will need to be moved outside of the `queueWork` call.\n // This introduces complexity regarding tracking of timing and start/end logging, however.\n\n if (this._runPending) {\n if (abortSignal.aborted) {\n innerState.status = OperationStatus.Aborted;\n break;\n } else {\n context.terminal.writeLine(`Immediate rerun requested. Executing.`);\n }\n }\n }\n\n state.stopwatch.stop();\n context.afterExecute(this, state);\n }, /* priority */ this.criticalPathLength ?? 0);\n\n return state.status;\n }\n}\n"]}
1
+ {"version":3,"file":"Operation.js","sourceRoot":"","sources":["../src/Operation.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,oEAA6E;AAE7E,2CAAwC;AAQxC,uDAAoD;AAgEpD;;;;;;;;GAQG;AACH,MAAa,SAAS;IAyFpB,YAAmB,OAA2B;QAxF9C;;WAEG;QACa,iBAAY,GAAmB,IAAI,GAAG,EAAa,CAAC;QACpE;;WAEG;QACa,cAAS,GAAmB,IAAI,GAAG,EAAa,CAAC;QAUjE;;;WAGG;QACI,WAAM,GAAiC,SAAS,CAAC;QAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA4BG;QACI,uBAAkB,GAAuB,SAAS,CAAC;QAe1D;;WAEG;QACI,cAAS,GAAgC,SAAS,CAAC;QAE1D;;WAEG;QACI,UAAK,GAAgC,SAAS,CAAC;QAEtD;;WAEG;QACK,aAAQ,GAAyC,SAAS,CAAC;QAEnE;;;WAGG;QACK,gBAAW,GAAY,IAAI,CAAC;QAGlC,IAAI,CAAC,SAAS,GAAG,OAAO,EAAE,SAAS,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI,CAAC;IAC5B,CAAC;IAEM,aAAa,CAAC,UAAqB;QACxC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAClC,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAEM,gBAAgB,CAAC,UAAqB;QAC3C,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,C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sBAAsB;gBAEtB,6FAA6F;gBAC7F,gGAAgG;gBAChG,qGAAqG;gBACrG,0FAA0F;gBAE1F,IAAI,IAAI,CAAC,WAAW,EAAE;oBACpB,IAAI,WAAW,CAAC,OAAO,EAAE;wBACvB,UAAU,CAAC,MAAM,GAAG,iCAAe,CAAC,OAAO,CAAC;wBAC5C,MAAM;qBACP;yBAAM;wBACL,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,uCAAuC,CAAC,CAAC;qBACrE;iBACF;aACF;YAED,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;YACvB,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAElC,OAAO,KAAK,CAAC,MAAM,CAAC;QACtB,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC,kBAAkB,IAAI,CAAC,CAAC,CAAC;QAEhD,OAAO,KAAK,CAAC,MAAM,CAAC;IACtB,CAAC;CACF;AAnQD,8BAmQC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { InternalError, type ITerminal } from '@rushstack/node-core-library';\n\nimport { Stopwatch } from './Stopwatch';\nimport type {\n IOperationRunner,\n IOperationRunnerContext,\n IOperationState,\n IOperationStates\n} from './IOperationRunner';\nimport type { OperationError } from './OperationError';\nimport { OperationStatus } from './OperationStatus';\n\n/**\n * Options for constructing a new Operation.\n * @beta\n */\nexport interface IOperationOptions {\n /**\n * The name of this operation, for logging.\n */\n name?: string | undefined;\n\n /**\n * The group that this operation belongs to. Will be used for logging and duration tracking.\n */\n groupName?: string | undefined;\n\n /**\n * When the scheduler is ready to process this `Operation`, the `runner` implements the actual work of\n * running the operation.\n */\n runner?: IOperationRunner | undefined;\n\n /**\n * The weight used by the scheduler to determine order of execution.\n */\n weight?: number | undefined;\n}\n\n/**\n * Information provided to `executeAsync` by the `OperationExecutionManager`.\n *\n * @beta\n */\nexport interface IExecuteOperationContext extends Omit<IOperationRunnerContext, 'isFirstRun' | 'requestRun'> {\n /**\n * Function to invoke before execution of an operation, for logging.\n */\n beforeExecute(operation: Operation, state: IOperationState): void;\n\n /**\n * Function to invoke after execution of an operation, for logging.\n */\n afterExecute(operation: Operation, state: IOperationState): void;\n\n /**\n * Function used to schedule the concurrency-limited execution of an operation.\n *\n * Will return OperationStatus.Aborted if execution is aborted before the task executes.\n */\n queueWork(workFn: () => Promise<OperationStatus>, priority: number): Promise<OperationStatus>;\n\n /**\n * A callback to the overarching orchestrator to request that the operation be invoked again.\n * Used in watch mode to signal that inputs have changed.\n */\n requestRun?: (requestor?: string) => void;\n\n /**\n * Terminal to write output to.\n */\n terminal: ITerminal;\n}\n\n/**\n * The `Operation` class is a node in the dependency graph of work that needs to be scheduled by the\n * `OperationExecutionManager`. Each `Operation` has a `runner` member of type `IOperationRunner`, whose\n * implementation manages the actual process of running a single operation.\n *\n * The graph of `Operation` instances will be cloned into a separate execution graph after processing.\n *\n * @beta\n */\nexport class Operation implements IOperationStates {\n /**\n * A set of all dependencies which must be executed before this operation is complete.\n */\n public readonly dependencies: Set<Operation> = new Set<Operation>();\n /**\n * A set of all operations that wait for this operation.\n */\n public readonly consumers: Set<Operation> = new Set<Operation>();\n /**\n * If specified, the name of a grouping to which this Operation belongs, for logging start and end times.\n */\n public readonly groupName: string | undefined;\n /**\n * The name of this operation, for logging.\n */\n public readonly name: string | undefined;\n\n /**\n * When the scheduler is ready to process this `Operation`, the `runner` implements the actual work of\n * running the operation.\n */\n public runner: IOperationRunner | undefined = undefined;\n\n /**\n * This number represents how far away this Operation is from the furthest \"root\" operation (i.e.\n * an operation with no consumers). This helps us to calculate the critical path (i.e. the\n * longest chain of projects which must be executed in order, thereby limiting execution speed\n * of the entire operation tree.\n *\n * This number is calculated via a memoized depth-first search, and when choosing the next\n * operation to execute, the operation with the highest criticalPathLength is chosen.\n *\n * Example:\n * (0) A\n * \\\\\n * (1) B C (0) (applications)\n * \\\\ /|\\\\\n * \\\\ / | \\\\\n * (2) D | X (1) (utilities)\n * | / \\\\\n * |/ \\\\\n * (2) Y Z (2) (other utilities)\n *\n * All roots (A & C) have a criticalPathLength of 0.\n * B has a score of 1, since A depends on it.\n * D has a score of 2, since we look at the longest chain (e.g D-\\>B-\\>A is longer than D-\\>C)\n * X has a score of 1, since the only package which depends on it is A\n * Z has a score of 2, since only X depends on it, and X has a score of 1\n * Y has a score of 2, since the chain Y-\\>X-\\>C is longer than Y-\\>C\n *\n * The algorithm is implemented in AsyncOperationQueue.ts as calculateCriticalPathLength()\n */\n public criticalPathLength: number | undefined = undefined;\n\n /**\n * The weight for this operation. This scalar is the contribution of this operation to the\n * `criticalPathLength` calculation above. Modify to indicate the following:\n * - `weight` === 1: indicates that this operation has an average duration\n * - `weight` &gt; 1: indicates that this operation takes longer than average and so the scheduler\n * should try to favor starting it over other, shorter operations. An example might be an operation that\n * bundles an entire application and runs whole-program optimization.\n * - `weight` &lt; 1: indicates that this operation takes less time than average and so the scheduler\n * should favor other, longer operations over it. An example might be an operation to unpack a cached\n * output, or an operation using NullOperationRunner, which might use a value of 0.\n */\n public weight: number;\n\n /**\n * The state of this operation the previous time a manager was invoked.\n */\n public lastState: IOperationState | undefined = undefined;\n\n /**\n * The current state of this operation\n */\n public state: IOperationState | undefined = undefined;\n\n /**\n * A cached execution promise for the current OperationExecutionManager invocation of this operation.\n */\n private _promise: Promise<OperationStatus> | undefined = undefined;\n\n /**\n * If true, then a run of this operation is currently wanted.\n * This is used to track state from the `requestRun` callback passed to the runner.\n */\n private _runPending: boolean = true;\n\n public constructor(options?: IOperationOptions) {\n this.groupName = options?.groupName;\n this.runner = options?.runner;\n this.weight = options?.weight || 1;\n this.name = options?.name;\n }\n\n public addDependency(dependency: Operation): void {\n this.dependencies.add(dependency);\n dependency.consumers.add(this);\n }\n\n public deleteDependency(dependency: Operation): void {\n this.dependencies.delete(dependency);\n dependency.consumers.delete(this);\n }\n\n public reset(): void {\n // Reset operation state\n this.lastState = this.state;\n\n this.state = {\n status: this.dependencies.size > 0 ? OperationStatus.Waiting : OperationStatus.Ready,\n hasBeenRun: this.lastState?.hasBeenRun ?? false,\n error: undefined,\n stopwatch: new Stopwatch()\n };\n\n this._promise = undefined;\n this._runPending = true;\n }\n\n /**\n * @internal\n */\n public async _executeAsync(context: IExecuteOperationContext): Promise<OperationStatus> {\n const { state } = this;\n if (!state) {\n throw new Error(`Operation state has not been initialized.`);\n }\n\n if (!this._promise) {\n this._promise = this._executeInnerAsync(context, state);\n }\n\n return this._promise;\n }\n\n private async _executeInnerAsync(\n context: IExecuteOperationContext,\n rawState: IOperationState\n ): Promise<OperationStatus> {\n const state: IOperationState = rawState;\n const { runner } = this;\n\n const dependencyResults: PromiseSettledResult<OperationStatus>[] = await Promise.allSettled(\n Array.from(this.dependencies, (dependency: Operation) => dependency._executeAsync(context))\n );\n\n const { abortSignal, requestRun, queueWork } = context;\n\n if (abortSignal.aborted) {\n state.status = OperationStatus.Aborted;\n return state.status;\n }\n\n for (const result of dependencyResults) {\n if (\n result.status === 'rejected' ||\n result.value === OperationStatus.Blocked ||\n result.value === OperationStatus.Failure\n ) {\n state.status = OperationStatus.Blocked;\n return state.status;\n }\n }\n\n state.status = OperationStatus.Ready;\n\n const innerContext: IOperationRunnerContext = {\n abortSignal,\n isFirstRun: !state.hasBeenRun,\n requestRun: requestRun\n ? () => {\n switch (this.state?.status) {\n case OperationStatus.Waiting:\n case OperationStatus.Ready:\n case OperationStatus.Executing:\n // If current status has not yet resolved to a fixed value,\n // re-executing this operation does not require a full rerun\n // of the operation graph. Simply mark that a run is requested.\n\n // This variable is on the Operation instead of the\n // containing closure to deal with scenarios in which\n // the runner hangs on to an old copy of the callback.\n this._runPending = true;\n return;\n\n case OperationStatus.Blocked:\n case OperationStatus.Aborted:\n case OperationStatus.Failure:\n case OperationStatus.NoOp:\n case OperationStatus.Success:\n // The requestRun callback is assumed to remain constant\n // throughout the lifetime of the process, so it is safe\n // to capture here.\n return requestRun(this.name);\n default:\n // This line is here to enforce exhaustiveness\n const currentStatus: undefined = this.state?.status;\n throw new InternalError(`Unexpected status: ${currentStatus}`);\n }\n }\n : undefined\n };\n\n // eslint-disable-next-line require-atomic-updates\n state.status = await queueWork(async (): Promise<OperationStatus> => {\n // Redundant variable to satisfy require-atomic-updates\n const innerState: IOperationState = state;\n\n if (abortSignal.aborted) {\n innerState.status = OperationStatus.Aborted;\n return innerState.status;\n }\n\n context.beforeExecute(this, innerState);\n\n innerState.stopwatch.start();\n innerState.status = OperationStatus.Executing;\n // Mark that the operation has been started at least once.\n innerState.hasBeenRun = true;\n\n while (this._runPending) {\n this._runPending = false;\n try {\n // We don't support aborting in the middle of a runner's execution.\n innerState.status = runner ? await runner.executeAsync(innerContext) : OperationStatus.NoOp;\n } catch (error) {\n innerState.status = OperationStatus.Failure;\n innerState.error = error as OperationError;\n }\n\n // Since runner.executeAsync is async, a change could have occurred that requires re-execution\n // This operation is still active, so can re-execute immediately, rather than forcing a whole\n // new execution pass.\n\n // As currently written, this does mean that if a job is scheduled with higher priority while\n // this operation is still executing, it will still wait for this retry. This may not be desired\n // and if it becomes a problem, the retry loop will need to be moved outside of the `queueWork` call.\n // This introduces complexity regarding tracking of timing and start/end logging, however.\n\n if (this._runPending) {\n if (abortSignal.aborted) {\n innerState.status = OperationStatus.Aborted;\n break;\n } else {\n context.terminal.writeLine(`Immediate rerun requested. Executing.`);\n }\n }\n }\n\n state.stopwatch.stop();\n context.afterExecute(this, state);\n\n return state.status;\n }, /* priority */ this.criticalPathLength ?? 0);\n\n return state.status;\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import type { ITerminal } from '@rushstack/node-core-library';
2
+ import { type ITerminal } from '@rushstack/node-core-library';
3
3
  import type { Operation } from './Operation';
4
4
  import { OperationStatus } from './OperationStatus';
5
5
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"OperationExecutionManager.d.ts","sourceRoot":"","sources":["../src/OperationExecutionManager.ts"],"names":[],"mappings":";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AyB;IACpC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAoC;IACvE;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAS;gBAE7B,UAAU,EAAE,WAAW,CAAC,SAAS,CAAC;IAqCrD;;;OAGG;IACU,YAAY,CAAC,gBAAgB,EAAE,0BAA0B,GAAG,OAAO,CAAC,eAAe,CAAC;CA+GlG"}
@@ -3,9 +3,11 @@
3
3
  // See LICENSE in the project root for license information.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.OperationExecutionManager = void 0;
6
+ const node_core_library_1 = require("@rushstack/node-core-library");
6
7
  const OperationGroupRecord_1 = require("./OperationGroupRecord");
7
8
  const OperationStatus_1 = require("./OperationStatus");
8
9
  const calculateCriticalPath_1 = require("./calculateCriticalPath");
10
+ const WorkQueue_1 = require("./WorkQueue");
9
11
  /**
10
12
  * A class which manages the execution of a set of tasks with interdependencies.
11
13
  * Initially, and at the end of each task execution, all unblocked tasks
@@ -50,6 +52,9 @@ class OperationExecutionManager {
50
52
  async executeAsync(executionOptions) {
51
53
  let hasReportedFailures = false;
52
54
  const { abortSignal, parallelism, terminal, requestRun } = executionOptions;
55
+ if (abortSignal.aborted) {
56
+ return OperationStatus_1.OperationStatus.Aborted;
57
+ }
53
58
  const startedGroups = new Set();
54
59
  const finishedGroups = new Set();
55
60
  const maxParallelism = Math.min(this._operations.length, parallelism);
@@ -61,14 +66,15 @@ class OperationExecutionManager {
61
66
  operation.reset();
62
67
  }
63
68
  terminal.writeVerboseLine(`Executing a maximum of ${maxParallelism} simultaneous tasks...`);
69
+ const workQueueAbortController = new AbortController();
70
+ abortSignal.addEventListener('abort', () => workQueueAbortController.abort(), { once: true });
71
+ const workQueue = new WorkQueue_1.WorkQueue(workQueueAbortController.signal);
64
72
  const executionContext = {
65
73
  terminal,
66
74
  abortSignal,
67
75
  requestRun,
68
76
  queueWork: (workFn, priority) => {
69
- // TODO: Update to throttle parallelism
70
- // Can just be a standard priority queue from async
71
- return workFn();
77
+ return workQueue.pushAsync(workFn, priority);
72
78
  },
73
79
  beforeExecute: (operation) => {
74
80
  // Initialize group if uninitialized and log the group name
@@ -112,7 +118,13 @@ class OperationExecutionManager {
112
118
  }
113
119
  }
114
120
  };
121
+ const workQueuePromise = node_core_library_1.Async.forEachAsync(workQueue, (workFn) => workFn(), {
122
+ concurrency: maxParallelism
123
+ });
115
124
  await Promise.all(this._operations.map((record) => record._executeAsync(executionContext)));
125
+ // Terminate queue execution.
126
+ workQueueAbortController.abort();
127
+ await workQueuePromise;
116
128
  const finalStatus = this._trackedOperationCount === 0
117
129
  ? OperationStatus_1.OperationStatus.NoOp
118
130
  : abortSignal.aborted
@@ -1 +1 @@
1
- {"version":3,"file":"OperationExecutionManager.js","sourceRoot":"","sources":["../src/OperationExecutionManager.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAM3D,iEAA8D;AAC9D,uDAAoD;AACpD,mEAAuE;AAevE;;;;;;;GAOG;AACH,MAAa,yBAAyB;IAgBpC,YAAmB,UAAkC;QACnD,MAAM,iBAAiB,GAAsC,IAAI,GAAG,EAAE,CAAC;QACvE,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;QAE5C,IAAI,qBAAqB,GAAW,CAAC,CAAC;QACtC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE;YAClC,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;YAChC,IAAI,KAAK,GAAqC,SAAS,CAAC;YACxD,IAAI,SAAS,IAAI,CAAC,CAAC,KAAK,GAAG,iBAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE;gBAC5D,KAAK,GAAG,IAAI,2CAAoB,CAAC,SAAS,CAAC,CAAC;gBAC5C,iBAAiB,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;aACzC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ENSE in the project root for license information.\n\nimport type { ITerminal } from '@rushstack/node-core-library';\n\nimport type { IOperationState } from './IOperationRunner';\nimport type { IExecuteOperationContext, Operation } from './Operation';\nimport { OperationGroupRecord } from './OperationGroupRecord';\nimport { OperationStatus } from './OperationStatus';\nimport { calculateCriticalPathLengths } from './calculateCriticalPath';\n\n/**\n * Options for the current run.\n *\n * @beta\n */\nexport interface IOperationExecutionOptions {\n abortSignal: AbortSignal;\n parallelism: number;\n terminal: ITerminal;\n\n requestRun?: (requestor?: string) => void;\n}\n\n/**\n * A class which manages the execution of a set of tasks with interdependencies.\n * Initially, and at the end of each task execution, all unblocked tasks\n * are added to a ready queue which is then executed. This is done continually until all\n * tasks are complete, or prematurely fails if any of the tasks fail.\n *\n * @beta\n */\nexport class OperationExecutionManager {\n /**\n * The set of operations that will be executed\n */\n private readonly _operations: Operation[];\n /**\n * Group records are metadata-only entities used for tracking the start and end of a set of related tasks.\n * This is the only extent to which the operation graph is aware of Heft phases.\n */\n private readonly _groupRecordByName: Map<string, OperationGroupRecord>;\n /**\n * The total number of non-silent operations in the graph.\n * Silent operations are generally used to simplify the construction of the graph.\n */\n private readonly _trackedOperationCount: number;\n\n public constructor(operations: ReadonlySet<Operation>) {\n const groupRecordByName: Map<string, OperationGroupRecord> = new Map();\n this._groupRecordByName = groupRecordByName;\n\n let trackedOperationCount: number = 0;\n for (const operation of operations) {\n const { groupName } = operation;\n let group: OperationGroupRecord | undefined = undefined;\n if (groupName && !(group = groupRecordByName.get(groupName))) {\n group = new OperationGroupRecord(groupName);\n groupRecordByName.set(groupName, group);\n }\n\n group?.addOperation(operation);\n\n if (!operation.runner?.silent) {\n // Only count non-silent operations\n trackedOperationCount++;\n }\n }\n\n this._trackedOperationCount = trackedOperationCount;\n\n this._operations = calculateCriticalPathLengths(operations);\n\n for (const consumer of operations) {\n for (const dependency of consumer.dependencies) {\n if (!operations.has(dependency)) {\n throw new Error(\n `Operation ${JSON.stringify(consumer.name)} declares a dependency on operation ` +\n `${JSON.stringify(dependency.name)} that is not in the set of operations to execute.`\n );\n }\n }\n }\n }\n\n /**\n * Executes all operations which have been registered, returning a promise which is resolved when all the\n * operations are completed successfully, or rejects when any operation fails.\n */\n public async executeAsync(executionOptions: IOperationExecutionOptions): Promise<OperationStatus> {\n let hasReportedFailures: boolean = false;\n\n const { abortSignal, parallelism, terminal, requestRun } = executionOptions;\n\n const startedGroups: Set<OperationGroupRecord> = new Set();\n const finishedGroups: Set<OperationGroupRecord> = new Set();\n\n const maxParallelism: number = Math.min(this._operations.length, parallelism);\n const groupRecords: Map<string, OperationGroupRecord> = this._groupRecordByName;\n for (const groupRecord of groupRecords.values()) {\n groupRecord.reset();\n }\n\n for (const operation of this._operations) {\n operation.reset();\n }\n\n terminal.writeVerboseLine(`Executing a maximum of ${maxParallelism} simultaneous tasks...`);\n\n const executionContext: IExecuteOperationContext = {\n terminal,\n abortSignal,\n\n requestRun,\n\n queueWork: <T>(workFn: () => Promise<T>, priority: number): Promise<T> => {\n // TODO: Update to throttle parallelism\n // Can just be a standard priority queue from async\n return workFn();\n },\n\n beforeExecute: (operation: Operation): void => {\n // Initialize group if uninitialized and log the group name\n const { groupName } = operation;\n const groupRecord: OperationGroupRecord | undefined = groupName\n ? groupRecords.get(groupName)\n : undefined;\n if (groupRecord && !startedGroups.has(groupRecord)) {\n startedGroups.add(groupRecord);\n groupRecord.startTimer();\n terminal.writeLine(` ---- ${groupRecord.name} started ---- `);\n }\n },\n\n afterExecute: (operation: Operation, state: IOperationState): void => {\n const { groupName } = operation;\n const groupRecord: OperationGroupRecord | undefined = groupName\n ? groupRecords.get(groupName)\n : undefined;\n if (groupRecord) {\n groupRecord.setOperationAsComplete(operation, state);\n }\n\n if (state.status === OperationStatus.Failure) {\n // This operation failed. Mark it as such and all reachable dependents as blocked.\n // Failed operations get reported, even if silent.\n // Generally speaking, silent operations shouldn't be able to fail, so this is a safety measure.\n const message: string | undefined = state.error?.message;\n if (message) {\n terminal.writeErrorLine(message);\n }\n hasReportedFailures = true;\n }\n\n // Log out the group name and duration if it is the last operation in the group\n if (groupRecord?.finished && !finishedGroups.has(groupRecord)) {\n finishedGroups.add(groupRecord);\n const finishedLoggingWord: string = groupRecord.hasFailures\n ? 'encountered an error'\n : groupRecord.hasCancellations\n ? 'cancelled'\n : 'finished';\n terminal.writeLine(\n ` ---- ${groupRecord.name} ${finishedLoggingWord} (${groupRecord.duration.toFixed(3)}s) ---- `\n );\n }\n }\n };\n\n await Promise.all(this._operations.map((record: Operation) => record._executeAsync(executionContext)));\n\n const finalStatus: OperationStatus =\n this._trackedOperationCount === 0\n ? OperationStatus.NoOp\n : abortSignal.aborted\n ? OperationStatus.Aborted\n : hasReportedFailures\n ? OperationStatus.Failure\n : OperationStatus.Success;\n\n return finalStatus;\n }\n}\n"]}
1
+ {"version":3,"file":"OperationExecutionManager.js","sourceRoot":"","sources":["../src/OperationExecutionManager.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,oEAAqE;AAIrE,iEAA8D;AAC9D,uDAAoD;AACpD,mEAAuE;AACvE,2CAAwC;AAexC;;;;;;;GAOG;AACH,MAAa,yBAAyB;IAgBpC,YAAmB,UAAkC;QACnD,MAAM,iBAAiB,GAAsC,IAAI,GAAG,EAAE,CAAC;QACvE,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;QAE5C,IAAI,qBAAqB,GAAW,CAAC,CAAC;QACtC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE;YAClC,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;YAChC,IAAI,KAAK,GAAqC,SAAS,CAAC;YACxD,IAAI,SAAS,IAAI,CAAC,CAAC,KAAK,GAAG,iBAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE;gBAC5D,KAAK,GAAG,IAAI,2CAAoB,CAAC,SAAS,CAAC,CAAC;gBAC5C,iBAAiB,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC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AC,WAAW,CAAC,GAAG,CAAC,CAAC,MAAiB,EAAE,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;QAEvG,6BAA6B;QAC7B,wBAAwB,CAAC,KAAK,EAAE,CAAC;QACjC,MAAM,gBAAgB,CAAC;QAEvB,MAAM,WAAW,GACf,IAAI,CAAC,sBAAsB,KAAK,CAAC;YAC/B,CAAC,CAAC,iCAAe,CAAC,IAAI;YACtB,CAAC,CAAC,WAAW,CAAC,OAAO;gBACrB,CAAC,CAAC,iCAAe,CAAC,OAAO;gBACzB,CAAC,CAAC,mBAAmB;oBACrB,CAAC,CAAC,iCAAe,CAAC,OAAO;oBACzB,CAAC,CAAC,iCAAe,CAAC,OAAO,CAAC;QAE9B,OAAO,WAAW,CAAC;IACrB,CAAC;CACF;AAxKD,8DAwKC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { Async, type ITerminal } from '@rushstack/node-core-library';\n\nimport type { IOperationState } from './IOperationRunner';\nimport type { IExecuteOperationContext, Operation } from './Operation';\nimport { OperationGroupRecord } from './OperationGroupRecord';\nimport { OperationStatus } from './OperationStatus';\nimport { calculateCriticalPathLengths } from './calculateCriticalPath';\nimport { WorkQueue } from './WorkQueue';\n\n/**\n * Options for the current run.\n *\n * @beta\n */\nexport interface IOperationExecutionOptions {\n abortSignal: AbortSignal;\n parallelism: number;\n terminal: ITerminal;\n\n requestRun?: (requestor?: string) => void;\n}\n\n/**\n * A class which manages the execution of a set of tasks with interdependencies.\n * Initially, and at the end of each task execution, all unblocked tasks\n * are added to a ready queue which is then executed. This is done continually until all\n * tasks are complete, or prematurely fails if any of the tasks fail.\n *\n * @beta\n */\nexport class OperationExecutionManager {\n /**\n * The set of operations that will be executed\n */\n private readonly _operations: Operation[];\n /**\n * Group records are metadata-only entities used for tracking the start and end of a set of related tasks.\n * This is the only extent to which the operation graph is aware of Heft phases.\n */\n private readonly _groupRecordByName: Map<string, OperationGroupRecord>;\n /**\n * The total number of non-silent operations in the graph.\n * Silent operations are generally used to simplify the construction of the graph.\n */\n private readonly _trackedOperationCount: number;\n\n public constructor(operations: ReadonlySet<Operation>) {\n const groupRecordByName: Map<string, OperationGroupRecord> = new Map();\n this._groupRecordByName = groupRecordByName;\n\n let trackedOperationCount: number = 0;\n for (const operation of operations) {\n const { groupName } = operation;\n let group: OperationGroupRecord | undefined = undefined;\n if (groupName && !(group = groupRecordByName.get(groupName))) {\n group = new OperationGroupRecord(groupName);\n groupRecordByName.set(groupName, group);\n }\n\n group?.addOperation(operation);\n\n if (!operation.runner?.silent) {\n // Only count non-silent operations\n trackedOperationCount++;\n }\n }\n\n this._trackedOperationCount = trackedOperationCount;\n\n this._operations = calculateCriticalPathLengths(operations);\n\n for (const consumer of operations) {\n for (const dependency of consumer.dependencies) {\n if (!operations.has(dependency)) {\n throw new Error(\n `Operation ${JSON.stringify(consumer.name)} declares a dependency on operation ` +\n `${JSON.stringify(dependency.name)} that is not in the set of operations to execute.`\n );\n }\n }\n }\n }\n\n /**\n * Executes all operations which have been registered, returning a promise which is resolved when all the\n * operations are completed successfully, or rejects when any operation fails.\n */\n public async executeAsync(executionOptions: IOperationExecutionOptions): Promise<OperationStatus> {\n let hasReportedFailures: boolean = false;\n\n const { abortSignal, parallelism, terminal, requestRun } = executionOptions;\n\n if (abortSignal.aborted) {\n return OperationStatus.Aborted;\n }\n\n const startedGroups: Set<OperationGroupRecord> = new Set();\n const finishedGroups: Set<OperationGroupRecord> = new Set();\n\n const maxParallelism: number = Math.min(this._operations.length, parallelism);\n const groupRecords: Map<string, OperationGroupRecord> = this._groupRecordByName;\n for (const groupRecord of groupRecords.values()) {\n groupRecord.reset();\n }\n\n for (const operation of this._operations) {\n operation.reset();\n }\n\n terminal.writeVerboseLine(`Executing a maximum of ${maxParallelism} simultaneous tasks...`);\n\n const workQueueAbortController: AbortController = new AbortController();\n abortSignal.addEventListener('abort', () => workQueueAbortController.abort(), { once: true });\n const workQueue: WorkQueue = new WorkQueue(workQueueAbortController.signal);\n\n const executionContext: IExecuteOperationContext = {\n terminal,\n abortSignal,\n\n requestRun,\n\n queueWork: (workFn: () => Promise<OperationStatus>, priority: number): Promise<OperationStatus> => {\n return workQueue.pushAsync(workFn, priority);\n },\n\n beforeExecute: (operation: Operation): void => {\n // Initialize group if uninitialized and log the group name\n const { groupName } = operation;\n const groupRecord: OperationGroupRecord | undefined = groupName\n ? groupRecords.get(groupName)\n : undefined;\n if (groupRecord && !startedGroups.has(groupRecord)) {\n startedGroups.add(groupRecord);\n groupRecord.startTimer();\n terminal.writeLine(` ---- ${groupRecord.name} started ---- `);\n }\n },\n\n afterExecute: (operation: Operation, state: IOperationState): void => {\n const { groupName } = operation;\n const groupRecord: OperationGroupRecord | undefined = groupName\n ? groupRecords.get(groupName)\n : undefined;\n if (groupRecord) {\n groupRecord.setOperationAsComplete(operation, state);\n }\n\n if (state.status === OperationStatus.Failure) {\n // This operation failed. Mark it as such and all reachable dependents as blocked.\n // Failed operations get reported, even if silent.\n // Generally speaking, silent operations shouldn't be able to fail, so this is a safety measure.\n const message: string | undefined = state.error?.message;\n if (message) {\n terminal.writeErrorLine(message);\n }\n hasReportedFailures = true;\n }\n\n // Log out the group name and duration if it is the last operation in the group\n if (groupRecord?.finished && !finishedGroups.has(groupRecord)) {\n finishedGroups.add(groupRecord);\n const finishedLoggingWord: string = groupRecord.hasFailures\n ? 'encountered an error'\n : groupRecord.hasCancellations\n ? 'cancelled'\n : 'finished';\n terminal.writeLine(\n ` ---- ${groupRecord.name} ${finishedLoggingWord} (${groupRecord.duration.toFixed(3)}s) ---- `\n );\n }\n }\n };\n\n const workQueuePromise: Promise<void> = Async.forEachAsync(\n workQueue,\n (workFn: () => Promise<void>) => workFn(),\n {\n concurrency: maxParallelism\n }\n );\n\n await Promise.all(this._operations.map((record: Operation) => record._executeAsync(executionContext)));\n\n // Terminate queue execution.\n workQueueAbortController.abort();\n await workQueuePromise;\n\n const finalStatus: OperationStatus =\n this._trackedOperationCount === 0\n ? OperationStatus.NoOp\n : abortSignal.aborted\n ? OperationStatus.Aborted\n : hasReportedFailures\n ? OperationStatus.Failure\n : OperationStatus.Success;\n\n return finalStatus;\n }\n}\n"]}
@@ -0,0 +1,15 @@
1
+ /// <reference types="node" />
2
+ import { OperationStatus } from './OperationStatus';
3
+ export declare class WorkQueue {
4
+ private readonly _queue;
5
+ private readonly _abortSignal;
6
+ private readonly _abortPromise;
7
+ private _pushPromise;
8
+ private _resolvePush;
9
+ private _resolvePushTimeout;
10
+ constructor(abortSignal: AbortSignal);
11
+ [Symbol.asyncIterator](): AsyncIterableIterator<() => Promise<void>>;
12
+ pushAsync(task: () => Promise<OperationStatus>, priority: number): Promise<OperationStatus>;
13
+ private _resolvePushDebounced;
14
+ }
15
+ //# sourceMappingURL=WorkQueue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WorkQueue.d.ts","sourceRoot":"","sources":["../src/WorkQueue.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAOpD,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0B;IACjD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAc;IAC3C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAE9C,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,mBAAmB,CAA6B;gBAErC,WAAW,EAAE,WAAW;IAa7B,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,qBAAqB,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAW3E,SAAS,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAalG,OAAO,CAAC,qBAAqB;CAS9B"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
+ // See LICENSE in the project root for license information.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.WorkQueue = void 0;
6
+ const node_core_library_1 = require("@rushstack/node-core-library");
7
+ const OperationStatus_1 = require("./OperationStatus");
8
+ class WorkQueue {
9
+ constructor(abortSignal) {
10
+ // Sort by priority descending. Thus the comparator returns a negative number if a has higher priority than b.
11
+ this._queue = new node_core_library_1.MinimumHeap((a, b) => b.priority - a.priority);
12
+ this._abortSignal = abortSignal;
13
+ this._abortPromise = abortSignal.aborted
14
+ ? Promise.resolve()
15
+ : new Promise((resolve) => {
16
+ abortSignal.addEventListener('abort', () => resolve(), { once: true });
17
+ });
18
+ [this._pushPromise, this._resolvePush] = node_core_library_1.Async.getSignal();
19
+ this._resolvePushTimeout = undefined;
20
+ }
21
+ async *[Symbol.asyncIterator]() {
22
+ while (!this._abortSignal.aborted) {
23
+ while (this._queue.size > 0) {
24
+ const item = this._queue.poll();
25
+ yield item.task;
26
+ }
27
+ await Promise.race([this._pushPromise, this._abortPromise]);
28
+ }
29
+ }
30
+ pushAsync(task, priority) {
31
+ return new Promise((resolve, reject) => {
32
+ this._queue.push({
33
+ task: () => task().then(resolve, reject),
34
+ priority
35
+ });
36
+ this._abortPromise.finally(() => resolve(OperationStatus_1.OperationStatus.Aborted));
37
+ this._resolvePushDebounced();
38
+ });
39
+ }
40
+ _resolvePushDebounced() {
41
+ if (!this._resolvePushTimeout) {
42
+ this._resolvePushTimeout = setTimeout(() => {
43
+ this._resolvePushTimeout = undefined;
44
+ this._resolvePush();
45
+ [this._pushPromise, this._resolvePush] = node_core_library_1.Async.getSignal();
46
+ });
47
+ }
48
+ }
49
+ }
50
+ exports.WorkQueue = WorkQueue;
51
+ //# sourceMappingURL=WorkQueue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WorkQueue.js","sourceRoot":"","sources":["../src/WorkQueue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IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;gBACf,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC;gBACxC,QAAQ;aACT,CAAC,CAAC;YAEH,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,iCAAe,CAAC,OAAO,CAAC,CAAC,CAAC;YAEnE,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC/B,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,qBAAqB;QAC3B,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE;YAC7B,IAAI,CAAC,mBAAmB,GAAG,UAAU,CAAC,GAAG,EAAE;gBACzC,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;gBACrC,IAAI,CAAC,YAAY,EAAE,CAAC;gBACpB,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,yBAAK,CAAC,SAAS,EAAE,CAAC;YAC7D,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF;AAvDD,8BAuDC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { Async, MinimumHeap } from '@rushstack/node-core-library';\n\nimport { OperationStatus } from './OperationStatus';\n\ninterface IQueueItem {\n task: () => Promise<void>;\n priority: number;\n}\n\nexport class WorkQueue {\n private readonly _queue: MinimumHeap<IQueueItem>;\n private readonly _abortSignal: AbortSignal;\n private readonly _abortPromise: Promise<void>;\n\n private _pushPromise: Promise<void>;\n private _resolvePush: () => void;\n private _resolvePushTimeout: NodeJS.Timeout | undefined;\n\n public constructor(abortSignal: AbortSignal) {\n // Sort by priority descending. Thus the comparator returns a negative number if a has higher priority than b.\n this._queue = new MinimumHeap((a: IQueueItem, b: IQueueItem) => b.priority - a.priority);\n this._abortSignal = abortSignal;\n this._abortPromise = abortSignal.aborted\n ? Promise.resolve()\n : new Promise<void>((resolve) => {\n abortSignal.addEventListener('abort', () => resolve(), { once: true });\n });\n [this._pushPromise, this._resolvePush] = Async.getSignal();\n this._resolvePushTimeout = undefined;\n }\n\n public async *[Symbol.asyncIterator](): AsyncIterableIterator<() => Promise<void>> {\n while (!this._abortSignal.aborted) {\n while (this._queue.size > 0) {\n const item: IQueueItem = this._queue.poll()!;\n yield item.task;\n }\n\n await Promise.race([this._pushPromise, this._abortPromise]);\n }\n }\n\n public pushAsync(task: () => Promise<OperationStatus>, priority: number): Promise<OperationStatus> {\n return new Promise((resolve, reject) => {\n this._queue.push({\n task: () => task().then(resolve, reject),\n priority\n });\n\n this._abortPromise.finally(() => resolve(OperationStatus.Aborted));\n\n this._resolvePushDebounced();\n });\n }\n\n private _resolvePushDebounced(): void {\n if (!this._resolvePushTimeout) {\n this._resolvePushTimeout = setTimeout(() => {\n this._resolvePushTimeout = undefined;\n this._resolvePush();\n [this._pushPromise, this._resolvePush] = Async.getSignal();\n });\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rushstack/operation-graph",
3
- "version": "0.1.2",
3
+ "version": "0.2.1",
4
4
  "description": "Library for managing and executing operations in a directed acyclic graph.",
5
5
  "main": "lib/index.js",
6
6
  "typings": "dist/operation-graph.d.ts",
@@ -11,11 +11,11 @@
11
11
  "directory": "libraries/operation-graph"
12
12
  },
13
13
  "dependencies": {
14
- "@rushstack/node-core-library": "3.60.1"
14
+ "@rushstack/node-core-library": "3.62.0"
15
15
  },
16
16
  "devDependencies": {
17
- "@rushstack/heft": "0.59.0",
18
- "@rushstack/heft-node-rig": "2.2.23",
17
+ "@rushstack/heft": "0.62.0",
18
+ "@rushstack/heft-node-rig": "2.3.2",
19
19
  "@types/heft-jest": "1.0.1",
20
20
  "@types/node": "18.17.15",
21
21
  "local-eslint-config": "1.0.0"