8000 Support percentage value for parallelism parameter · psy-repos-typescript/rushstack@4ce3dd7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4ce3dd7

Browse files
wberniclanton
authored andcommitted
Support percentage value for parallelism parameter
1 parent da9d490 commit 4ce3dd7

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

apps/rush-lib/src/cli/scriptActions/PhasedScriptAction.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,9 @@ export class PhasedScriptAction extends BaseScriptAction<IPhasedCommandConfig> {
342342
environmentVariable: EnvironmentVariableNames.RUSH_PARALLELISM,
343343
description:
344344
'Specifies the maximum number of concurrent processes to launch during a build.' +
345-
' The COUNT should be a positive integer or else the word "max" to specify a count that is equal to' +
346-
' the number of CPU cores. If this parameter is omitted, then the default value depends on the' +
347-
' operating system and number of CPU cores.'
345+
' The COUNT should be a positive integer, a percentage value (eg. "50%") or the word "max"' +
346+
' to specify a count that is equal to the number of CPU cores. If this parameter is omitted,' +
347+
' then the default value depends on the operating system and number of CPU cores.'
348348
});
349349
this._timelineParameter = this.defineFlagParameter({
350350
parameterLongName: '--timeline',

apps/rush-lib/src/logic/operations/OperationExecutionManager.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,24 @@ export class OperationExecutionManager {
157157
if (parallelism === 'max') {
158158
this._parallelism = numberOfCores;
159159
} else {
160-
const parallelismInt: number = parseInt(parallelism, 10);
160+
const parsed: number = parseInt(parallelism, 10);
161161

162-
if (isNaN(parallelismInt)) {
163-
throw new Error(`Invalid parallelism value of '${parallelism}', expected a number or 'max'`);
162+
if (isNaN(parsed)) {
163+
throw new Error(
164+
`Invalid parallelism value of '${parallelism}', expected a number, a percentage, or 'max'`
165+
);
166+
}
167+
168+
let parallelismInt: number = parsed > 0 ? parsed : 1;
169+
170+
if (
171+
typeof parallelism === 'string' &&
172+
parallelism.trim().endsWith('%') &&
173+
parsed > 0 &&
174+
parsed <= 100
175+
) {
176+
const workers: number = Math.floor((parsed / 100) * numberOfCores);
177+
parallelismInt = Math.max(workers, 1);
164178
}
165179

166180
this._parallelism = parallelismInt;

apps/rush-lib/src/logic/operations/test/OperationExecutionManager.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ describe(OperationExecutionManager.name, () => {
7878
});
7979
});
8080

81+
describe('Constructor', () => {
82+
it('createsWithPercentageBasedParallelism', () => {
83+
expect(
84+
() =>
85+
new OperationExecutionManager(new Set(), {
86+
quietMode: false,
87+
debugMode: false,
88+
parallelism: '50%',
89+
changedProjectsOnly: false,
90+
destination: mockWritable,
91+
repoCommandLineConfiguration: undefined!
92+
})
93+
).toBeInstanceOf(Function);
94+
});
95+
});
96+
8197
describe('Error logging', () => {
8298
beforeEach(() => {
8399
executionManagerOptions = {

apps/rush-lib/src/logic/operations/test/__snapshots__/OperationExecutionManager.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`OperationExecutionManager Constructor throwsErrorOnInvalidParallelism 1`] = `"Invalid para 4F85 llelism value of 'tequila', expected a number or 'max'"`;
3+
exports[`OperationExecutionManager Constructor throwsErrorOnInvalidParallelism 1`] = `"Invalid parallelism value of 'tequila', expected a number, a percentage, or 'max'"`;
44

55
exports[`OperationExecutionManager Error logging printedStderrAfterError 1`] = `"An error occurred."`;
66

0 commit comments

Comments
 (0)
0