@nrwl/nx-cloud 15.0.2 → 15.1.0-beta0
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.
- package/lib/core/api/error-reporter.api.js +36 -1
- package/lib/core/api/run-group.api.js +68 -1
- package/lib/core/error/print-invalid-runner-error.d.ts +1 -0
- package/lib/core/error/print-invalid-runner-error.js +17 -0
- package/lib/core/error/print-invalid-runner-error.js.map +1 -0
- package/lib/core/runners/cloud-enabled/cloud-enabled-life-cycle.js +109 -1
- package/lib/core/runners/cloud-enabled/cloud-enabled.runner.js +288 -1
- package/lib/core/runners/cloud-enabled/cloud-remote-cache.js +113 -1
- package/lib/core/runners/cloud-enabled/cloud-run.api.js +167 -1
- package/lib/core/runners/cloud-enabled/id-generator.js +16 -1
- package/lib/core/runners/distributed-agent/distributed-agent.api.js +79 -1
- package/lib/core/runners/distributed-agent/distributed-agent.impl.js +269 -1
- package/lib/core/runners/distributed-agent/distributed-agent.impl.js.map +1 -1
- package/lib/core/runners/distributed-execution/distributed-execution.api.js +143 -1
- package/lib/core/runners/distributed-execution/distributed-execution.runner.js +220 -1
- package/lib/core/runners/distributed-execution/split-task-graph-into-stages.js +37 -1
- package/lib/core/runners/distributed-execution/task-graph-creator.js +77 -1
- package/lib/utilities/distributed-task-execution-detection.js +1 -1
- package/lib/utilities/distributed-task-execution-detection.js.map +1 -1
- package/lib/utilities/environment.js +8 -9
- package/lib/utilities/environment.js.map +1 -1
- package/package.json +1 -1
- package/project.json +2 -1
|
@@ -1 +1,269 @@
|
|
|
1
|
-
const a6_0x29b4=['error','then','forEach','getTime','.lock','submitRunMetrics','This\x20can\x20also\x20be\x20a\x20false\x20positive\x20caused\x20by\x20agents\x20that\x20did\x20not\x20shut\x20down\x20correctly.','writeFileSync','message','/tasks-hashes-','readFileSync','API\x20Response','unlinkSync','Other\x20Nx\x20Cloud\x20Agents\x20Detected','completed','catch','We\x20have\x20detected\x20other\x20agents\x20running\x20in\x20this\x20workspace.\x20This\x20can\x20cause\x20unexpected\x20behavior.','__esModule','../../error/print-run-group-error','true','existsSync','maxParallel','params','We\x20have\x20detected\x20another\x20agent\x20with\x20this\x20ID\x20running\x20in\x20this\x20workspace.\x20This\x20should\x20not\x20happen.','target','/lockfiles','Command\x20execution\x20failed\x20(distributed\x20task\x20execution:\x20','configuration','DistributedAgentApi','execSync','readdirSync','floor','length','__awaiter','printRunGroupError','completedTasks','No\x20new\x20messages\x20received\x20after\x20','exit','projects','../../../utilities/metric-logger','map','options','VERBOSE_LOGGING','push','Duplicate\x20Agent\x20ID\x20Detected','./node_modules/.cache/nx','reset','Distributed\x20Execution\x20Terminated','/nx.json','CIRCLE_JOB','find','Critical\x20Error\x20in\x20Agent:\x20\x22','completeRunGroupWithError','projectName','Waiting...','Fetching\x20tasks...','criticalErrorMessage','apply','toString','Error:','NX_AGENT_NAME','NO_MESSAGES_TIMEOUT','../../../utilities/nx-imports','tasks','Waiter','child_process','../../../utilities/environment','\x20--projects=','Executing:\x20\x27','note','inherit','../../../utilities/waiter','join','cacheDirectory','next','retryDuring','value','parse','done','completedStatusCode','npx\x20nx\x20run-many\x20--target=','./distributed-agent.api','../../../utilities/create-unchanged-value-timeout','startAgent','completed:\x20','createUnchangedValueTimeout','RUN_GROUP_COMPLETED','status','wait','error:\x20','assign','\x20seconds','includes','getRunGroup','default','\x20--parallel\x20--max-parallel=','warn','strip-json-comments','number\x20of\x20tasks:\x20','executionId','mkdirSync','If\x20you\x20believe\x20this\x20is\x20the\x20case,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22.','retryDuring:\x20','status:\x20','maxParallel:\x20','defineProperty','Starting\x20an\x20agent\x20for\x20running\x20Nx\x20tasks','Agent\x20was\x20terminated\x20via\x20SIGTERM','DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE','CIRCLE_STAGE','SIGTERM','env'];(function(_0x447fc3,_0x29b4c2){const _0x4198d5=function(_0xf2e9c9){while(--_0xf2e9c9){_0x447fc3['push'](_0x447fc3['shift']());}};_0x4198d5(++_0x29b4c2);}(a6_0x29b4,0x184));const a6_0x4198=function(_0x447fc3,_0x29b4c2){_0x447fc3=_0x447fc3-0x0;let _0x4198d5=a6_0x29b4[_0x447fc3];return _0x4198d5;};'use strict';var __awaiter=this&&this[a6_0x4198('0x5d')]||function(_0x40a6c0,_0x5dd44d,_0x2e8967,_0x23480b){function _0x496a15(_0x4e9014){return _0x4e9014 instanceof _0x2e8967?_0x4e9014:new _0x2e8967(function(_0x4b07d0){_0x4b07d0(_0x4e9014);});}return new(_0x2e8967||(_0x2e8967=Promise))(function(_0xbdb28d,_0x34ba31){function _0x155d50(_0x56b52b){try{_0x598f5e(_0x23480b['next'](_0x56b52b));}catch(_0x5d653b){_0x34ba31(_0x5d653b);}}function _0x57c342(_0x1ff801){try{_0x598f5e(_0x23480b['throw'](_0x1ff801));}catch(_0x15e366){_0x34ba31(_0x15e366);}}function _0x598f5e(_0x630214){_0x630214[a6_0x4198('0x1a')]?_0xbdb28d(_0x630214[a6_0x4198('0x18')]):_0x496a15(_0x630214[a6_0x4198('0x18')])[a6_0x4198('0x3d')](_0x155d50,_0x57c342);}_0x598f5e((_0x23480b=_0x23480b[a6_0x4198('0x5')](_0x40a6c0,_0x5dd44d||[]))[a6_0x4198('0x16')]());});};Object[a6_0x4198('0x35')](exports,a6_0x4198('0x4d'),{'value':!![]});exports[a6_0x4198('0x1f')]=void 0x0;const child_process_1=require(a6_0x4198('0xd'));const fs_1=require('fs');const stripJsonComments=require(a6_0x4198('0x2d'));const create_unchanged_value_timeout_1=require(a6_0x4198('0x1e'));const environment_1=require(a6_0x4198('0xe'));const metric_logger_1=require(a6_0x4198('0x63'));const waiter_1=require(a6_0x4198('0x13'));const print_run_group_error_1=require(a6_0x4198('0x4e'));const distributed_agent_api_1=require(a6_0x4198('0x1d'));const {output,workspaceRoot}=require(a6_0x4198('0xa'));function executeTasks(_0x12b3a9,_0x588ae2){return __awaiter(this,void 0x0,void 0x0,function*(){let _0x42394f=0x0;let _0x3cdeae=null;const _0x47af82=(0x0,create_unchanged_value_timeout_1[a6_0x4198('0x21')])({'title':a6_0x4198('0x60')+environment_1[a6_0x4198('0x9')]/0x3e8+a6_0x4198('0x27'),'timeout':environment_1[a6_0x4198('0x9')]});const _0x111852=new waiter_1[(a6_0x4198('0xc'))]();let _0x3fc515=[];const _0x1968a9=new Date();let _0x3361df=![];while(!![]){if(environment_1['VERBOSE_LOGGING']){output['note']({'title':a6_0x4198('0x3')});}_0x3cdeae=yield _0x588ae2[a6_0x4198('0xb')](_0x3cdeae?_0x3cdeae[a6_0x4198('0x2f')]:null,_0x42394f,_0x3fc515);if(environment_1[a6_0x4198('0x66')]){output[a6_0x4198('0x11')]({'title':a6_0x4198('0x47'),'bodyLines':[a6_0x4198('0x20')+_0x3cdeae['completed'],a6_0x4198('0x33')+_0x3cdeae[a6_0x4198('0x23')],a6_0x4198('0x32')+_0x3cdeae[a6_0x4198('0x17')],'executionId:\x20'+_0x3cdeae[a6_0x4198('0x2f')],a6_0x4198('0x2e')+_0x3cdeae[a6_0x4198('0xb')][a6_0x4198('0x5c')],a6_0x4198('0x25')+_0x3cdeae[a6_0x4198('0x4')],a6_0x4198('0x34')+_0x3cdeae[a6_0x4198('0x51')]]});}if(_0x3cdeae[a6_0x4198('0x4')]){output[a6_0x4198('0x3c')]({'title':a6_0x4198('0x6b'),'bodyLines':[a6_0x4198('0x7'),_0x3cdeae[a6_0x4198('0x4')]]});process[a6_0x4198('0x61')](0x0);}if((_0x3cdeae===null||_0x3cdeae===void 0x0?void 0x0:_0x3cdeae[a6_0x4198('0x17')])&&(_0x3cdeae===null||_0x3cdeae===void 0x0?void 0x0:_0x3cdeae['retryDuring'])!==0x0&&!_0x3361df&&new Date()['getTime']()-_0x1968a9[a6_0x4198('0x3f')]()>_0x3cdeae[a6_0x4198('0x17')]){yield _0x111852['wait']();continue;}if((_0x3cdeae===null||_0x3cdeae===void 0x0?void 0x0:_0x3cdeae[a6_0x4198('0x23')])!==undefined){if(_0x3cdeae['status']===a6_0x4198('0x22')||_0x3cdeae[a6_0x4198('0x23')]==='NO_FURTHER_TASKS_TO_RUN'){return;}}else if(_0x3cdeae[a6_0x4198('0x4a')]){return;}_0x47af82(_0x3cdeae[a6_0x4198('0xb')][a6_0x4198('0x64')](_0x304625=>_0x304625['taskId'])[a6_0x4198('0x14')](''));if(!_0x3cdeae[a6_0x4198('0x2f')]){if(environment_1['VERBOSE_LOGGING']){output['note']({'title':a6_0x4198('0x2')});}yield _0x111852[a6_0x4198('0x24')]();_0x42394f=0x0;_0x3fc515=[];continue;}_0x111852[a6_0x4198('0x6a')]();_0x3361df=!![];const _0x383398=invokeTasksUsingRunMany(_0x12b3a9,_0x3cdeae[a6_0x4198('0x2f')],_0x3cdeae['tasks'],_0x3cdeae[a6_0x4198('0x51')]);_0x42394f=_0x383398[a6_0x4198('0x1b')];_0x3fc515=_0x383398[a6_0x4198('0x5f')];}});}function readCompletedTasks(_0x14e28f,_0xdecb79){const _0x358c54=a6_0x4198('0x56')+_0xdecb79+').\x20Tasks\x20hashes\x20haven\x27t\x20been\x20recorded.';let _0xd834b6;try{const _0x4a75f5=_0x14e28f[a6_0x4198('0x15')]||a6_0x4198('0x69');const _0x2dd8d0=_0x4a75f5+a6_0x4198('0x45')+_0xdecb79;_0xd834b6=JSON[a6_0x4198('0x19')]((0x0,fs_1[a6_0x4198('0x46')])(_0x2dd8d0)[a6_0x4198('0x6')]());(0x0,fs_1[a6_0x4198('0x48')])(_0x2dd8d0);}catch(_0x2b6a4f){throw new Error(_0x358c54);}if(_0xd834b6[a6_0x4198('0x5c')]==0x0){throw new Error(_0x358c54);}return _0xd834b6;}function invokeTasksUsingRunMany(_0x3ed701,_0xdca9e9,_0x34235a,_0x20f865){let _0xf2dd81=0x0;const _0x24620c=[];for(const _0x3b50db of groupByTarget(_0x34235a)){const _0x210dca=_0x3b50db[a6_0x4198('0x57')]?'--configuration='+_0x3b50db[a6_0x4198('0x57')]:'';const _0x36c326=_0x20f865>0x1?a6_0x4198('0x2b')+_0x20f865:'';const _0x5822f4=a6_0x4198('0x1c')+_0x3b50db['target']+'\x20'+_0x210dca+a6_0x4198('0xf')+_0x3b50db[a6_0x4198('0x62')][a6_0x4198('0x14')](',')+'\x20'+_0x3b50db[a6_0x4198('0x52')]+_0x36c326;if(environment_1[a6_0x4198('0x66')]){output[a6_0x4198('0x11')]({'title':a6_0x4198('0x10')+_0x5822f4+'\x27'});}try{(0x0,child_process_1[a6_0x4198('0x59')])(_0x5822f4,{'stdio':['ignore','inherit',a6_0x4198('0x12')],'env':Object[a6_0x4198('0x26')](Object[a6_0x4198('0x26')]({},process['env']),{'NX_CACHE_FAILURES':a6_0x4198('0x4f'),'NX_CLOUD_DISTRIBUTED_EXECUTION_ID':_0xdca9e9,'NX_STREAM_OUTPUT':'true','NX_PREFIX_OUTPUT':a6_0x4198('0x4f')})});_0x24620c['push'](...readCompletedTasks(_0x3ed701,_0xdca9e9));}catch(_0x9b9465){if(_0x9b9465[a6_0x4198('0x23')]===environment_1[a6_0x4198('0x38')]){throw _0x9b9465;}else{_0xf2dd81=0x1;_0x24620c['push'](...readCompletedTasks(_0x3ed701,_0xdca9e9));}}}return{'completedStatusCode':_0xf2dd81,'completedTasks':_0x24620c};}function groupByTarget(_0x385343){const _0x2af174=[];_0x385343[a6_0x4198('0x3e')](_0x593086=>{const _0x10be3e=_0x2af174[a6_0x4198('0x6e')](_0x551e22=>_0x551e22[a6_0x4198('0x54')]===_0x593086['target']&&_0x551e22[a6_0x4198('0x57')]===_0x593086['configuration']);if(_0x10be3e){_0x10be3e[a6_0x4198('0x62')]['push'](_0x593086[a6_0x4198('0x1')]);}else{_0x2af174[a6_0x4198('0x67')]({'target':_0x593086[a6_0x4198('0x54')],'projects':[_0x593086[a6_0x4198('0x1')]],'params':_0x593086[a6_0x4198('0x52')],'configuration':_0x593086['configuration']});}});return _0x2af174;}function getAgentName(){if(process[a6_0x4198('0x3b')][a6_0x4198('0x8')]!==undefined){return process[a6_0x4198('0x3b')][a6_0x4198('0x8')];}else if(process[a6_0x4198('0x3b')]['CIRCLECI']!==undefined&&process[a6_0x4198('0x3b')][a6_0x4198('0x39')]){return process[a6_0x4198('0x3b')][a6_0x4198('0x39')];}else if(process[a6_0x4198('0x3b')]['CIRCLECI']!==undefined&&process[a6_0x4198('0x3b')]['CIRCLE_JOB']){return process[a6_0x4198('0x3b')][a6_0x4198('0x6d')];}else{return'Agent\x20'+Math[a6_0x4198('0x5b')](Math['random']()*0x186a0);}}function createAgentLockfileAndSetUpListeners(_0x572570,_0x3208f7,_0x22b682){const _0x3cff02=_0x3208f7[a6_0x4198('0x15')]||'./node_modules/.cache/nx';const _0x9de6c5=_0x3cff02+a6_0x4198('0x55');const _0x1f1fcd=_0x9de6c5+'/'+_0x22b682+a6_0x4198('0x40');if(!(0x0,fs_1[a6_0x4198('0x50')])(_0x9de6c5)){(0x0,fs_1[a6_0x4198('0x30')])(_0x9de6c5,{'recursive':!![]});}const _0x59ee77=(0x0,fs_1[a6_0x4198('0x5a')])(_0x9de6c5);if(_0x59ee77[a6_0x4198('0x5c')]){if(_0x59ee77[a6_0x4198('0x28')](_0x22b682+a6_0x4198('0x40'))){output[a6_0x4198('0x3c')]({'title':a6_0x4198('0x68'),'bodyLines':[a6_0x4198('0x53'),'','End\x20all\x20currently\x20running\x20agents,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22,\x20and\x20try\x20again.']});process[a6_0x4198('0x61')](0x1);}output[a6_0x4198('0x2c')]({'title':a6_0x4198('0x49'),'bodyLines':[a6_0x4198('0x4c'),'',a6_0x4198('0x42'),a6_0x4198('0x31')]});}(0x0,fs_1[a6_0x4198('0x43')])(_0x1f1fcd,'');process['on'](a6_0x4198('0x61'),_0x4dc6fa=>{cleanupAgentLockfile(_0x1f1fcd,_0x4dc6fa);});process['on'](a6_0x4198('0x3a'),()=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x572570['completeRunGroupWithError'](a6_0x4198('0x37'));cleanupAgentLockfile(_0x1f1fcd,0x1);}));process['on']('SIGINT',()=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x572570[a6_0x4198('0x0')]('Agent\x20was\x20terminated\x20via\x20SIGINT');cleanupAgentLockfile(_0x1f1fcd,0x1);}));}function cleanupAgentLockfile(_0x3caac4,_0x4ad1c7){if((0x0,fs_1[a6_0x4198('0x50')])(_0x3caac4)){(0x0,fs_1[a6_0x4198('0x48')])(_0x3caac4);process['exit'](_0x4ad1c7);}}function startAgent(){return __awaiter(this,void 0x0,void 0x0,function*(){const _0xe29f77=(0x0,environment_1[a6_0x4198('0x29')])();if(!_0xe29f77){(0x0,print_run_group_error_1[a6_0x4198('0x5e')])();return process[a6_0x4198('0x61')](0x1);}output[a6_0x4198('0x11')]({'title':a6_0x4198('0x36')});const _0x3e0bd3=JSON[a6_0x4198('0x19')](stripJsonComments((0x0,fs_1[a6_0x4198('0x46')])(workspaceRoot+a6_0x4198('0x6c'))['toString']()))['tasksRunnerOptions'][a6_0x4198('0x2a')][a6_0x4198('0x65')];const _0x301e6a=getAgentName();const _0xa0c3da=new distributed_agent_api_1[(a6_0x4198('0x58'))](_0x3e0bd3,_0xe29f77,_0x301e6a);createAgentLockfileAndSetUpListeners(_0xa0c3da,_0x3e0bd3,_0x301e6a);return executeTasks(_0x3e0bd3,_0xa0c3da)[a6_0x4198('0x3d')](_0x271a6f=>__awaiter(this,void 0x0,void 0x0,function*(){yield(0x0,metric_logger_1[a6_0x4198('0x41')])(_0x3e0bd3);return _0x271a6f;}))[a6_0x4198('0x4b')](_0x1712eb=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0xa0c3da[a6_0x4198('0x0')](a6_0x4198('0x6f')+_0x1712eb[a6_0x4198('0x44')]+'\x22');throw _0x1712eb;}));});}exports[a6_0x4198('0x1f')]=startAgent;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.startAgent = void 0;
|
|
13
|
+
const child_process_1 = require("child_process");
|
|
14
|
+
const fs_1 = require("fs");
|
|
15
|
+
const stripJsonComments = require("strip-json-comments");
|
|
16
|
+
const create_unchanged_value_timeout_1 = require("../../../utilities/create-unchanged-value-timeout");
|
|
17
|
+
const environment_1 = require("../../../utilities/environment");
|
|
18
|
+
const metric_logger_1 = require("../../../utilities/metric-logger");
|
|
19
|
+
const waiter_1 = require("../../../utilities/waiter");
|
|
20
|
+
const print_run_group_error_1 = require("../../error/print-run-group-error");
|
|
21
|
+
const distributed_agent_api_1 = require("./distributed-agent.api");
|
|
22
|
+
const print_invalid_runner_error_1 = require("../../error/print-invalid-runner-error");
|
|
23
|
+
const { output, workspaceRoot } = require('../../../utilities/nx-imports');
|
|
24
|
+
function executeTasks(options, api) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
let completedStatusCode = 0;
|
|
27
|
+
let apiResponse = null;
|
|
28
|
+
const failIfSameTasksAfterTimeout = (0, create_unchanged_value_timeout_1.createUnchangedValueTimeout)({
|
|
29
|
+
title: `No new messages received after ${environment_1.NO_MESSAGES_TIMEOUT / 1000} seconds`,
|
|
30
|
+
timeout: environment_1.NO_MESSAGES_TIMEOUT,
|
|
31
|
+
});
|
|
32
|
+
const waiter = new waiter_1.Waiter();
|
|
33
|
+
let completedTasks = [];
|
|
34
|
+
const startTime = new Date();
|
|
35
|
+
let executedAnyTasks = false;
|
|
36
|
+
while (true) {
|
|
37
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
38
|
+
output.note({
|
|
39
|
+
title: 'Fetching tasks...',
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
apiResponse = yield api.tasks(apiResponse ? apiResponse.executionId : null, completedStatusCode, completedTasks);
|
|
43
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
44
|
+
output.note({
|
|
45
|
+
title: 'API Response',
|
|
46
|
+
bodyLines: [
|
|
47
|
+
`completed: ${apiResponse.completed}`,
|
|
48
|
+
`status: ${apiResponse.status}`,
|
|
49
|
+
`retryDuring: ${apiResponse.retryDuring}`,
|
|
50
|
+
`executionId: ${apiResponse.executionId}`,
|
|
51
|
+
`number of tasks: ${apiResponse.tasks.length}`,
|
|
52
|
+
`error: ${apiResponse.criticalErrorMessage}`,
|
|
53
|
+
`maxParallel: ${apiResponse.maxParallel}`,
|
|
54
|
+
],
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (apiResponse.criticalErrorMessage) {
|
|
58
|
+
output.error({
|
|
59
|
+
title: 'Distributed Execution Terminated',
|
|
60
|
+
bodyLines: ['Error:', apiResponse.criticalErrorMessage],
|
|
61
|
+
});
|
|
62
|
+
process.exit(0);
|
|
63
|
+
}
|
|
64
|
+
// run group is completed but it might be a rerun
|
|
65
|
+
// we will try several times before going further and
|
|
66
|
+
// completed the response
|
|
67
|
+
// we only do it if we haven't executed any tasks
|
|
68
|
+
if ((apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.retryDuring) &&
|
|
69
|
+
(apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.retryDuring) !== 0 &&
|
|
70
|
+
!executedAnyTasks &&
|
|
71
|
+
new Date().getTime() - startTime.getTime() > apiResponse.retryDuring) {
|
|
72
|
+
yield waiter.wait();
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if ((apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.status) !== undefined) {
|
|
76
|
+
if (apiResponse.status === 'RUN_GROUP_COMPLETED' ||
|
|
77
|
+
apiResponse.status === 'NO_FURTHER_TASKS_TO_RUN') {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if (apiResponse.completed) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// if status is present that use the status instead of completed, otherwise use completed
|
|
85
|
+
failIfSameTasksAfterTimeout(apiResponse.tasks.map((t) => t.taskId).join(''));
|
|
86
|
+
if (!apiResponse.executionId) {
|
|
87
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
88
|
+
output.note({
|
|
89
|
+
title: 'Waiting...',
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
yield waiter.wait();
|
|
93
|
+
completedStatusCode = 0;
|
|
94
|
+
completedTasks = [];
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
waiter.reset();
|
|
98
|
+
executedAnyTasks = true;
|
|
99
|
+
const r = invokeTasksUsingRunMany(options, apiResponse.executionId, apiResponse.tasks, apiResponse.maxParallel);
|
|
100
|
+
completedStatusCode = r.completedStatusCode;
|
|
101
|
+
completedTasks = r.completedTasks;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function readCompletedTasks(options, distributedExecutionId) {
|
|
106
|
+
const errorMessage = `Command execution failed (distributed task execution: ${distributedExecutionId}). Tasks hashes haven\'t been recorded.`;
|
|
107
|
+
let completedTasks;
|
|
108
|
+
try {
|
|
109
|
+
const cacheDirectory = options.cacheDirectory || './node_modules/.cache/nx';
|
|
110
|
+
const taskHashesFile = `${cacheDirectory}/tasks-hashes-${distributedExecutionId}`;
|
|
111
|
+
completedTasks = JSON.parse((0, fs_1.readFileSync)(taskHashesFile).toString());
|
|
112
|
+
// remove it such that if the next command crashes we don't read an obsolete file
|
|
113
|
+
(0, fs_1.unlinkSync)(taskHashesFile);
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
throw new Error(errorMessage);
|
|
117
|
+
}
|
|
118
|
+
if (completedTasks.length == 0) {
|
|
119
|
+
throw new Error(errorMessage);
|
|
120
|
+
}
|
|
121
|
+
return completedTasks;
|
|
122
|
+
}
|
|
123
|
+
function invokeTasksUsingRunMany(options, executionId, tasks, maxParallel) {
|
|
124
|
+
let completedStatusCode = 0;
|
|
125
|
+
const completedTasks = [];
|
|
126
|
+
for (const g of groupByTarget(tasks)) {
|
|
127
|
+
const config = g.configuration ? `--configuration=${g.configuration}` : ``;
|
|
128
|
+
const parallel = maxParallel > 1 ? ` --parallel --max-parallel=${maxParallel}` : ``;
|
|
129
|
+
// TODO use pnpx or yarn when needed
|
|
130
|
+
const command = `npx nx run-many --target=${g.target} ${config} --projects=${g.projects.join(',')} ${g.params}${parallel}`;
|
|
131
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
132
|
+
output.note({
|
|
133
|
+
title: `Executing: '${command}'`,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
(0, child_process_1.execSync)(command, {
|
|
138
|
+
stdio: ['ignore', 'inherit', 'inherit'],
|
|
139
|
+
env: Object.assign(Object.assign({}, process.env), { NX_CACHE_FAILURES: 'true', NX_CLOUD_DISTRIBUTED_EXECUTION_ID: executionId, NX_STREAM_OUTPUT: 'true', NX_PREFIX_OUTPUT: 'true' }),
|
|
140
|
+
});
|
|
141
|
+
completedTasks.push(...readCompletedTasks(options, executionId));
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
if (e.status === environment_1.DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE) {
|
|
145
|
+
throw e;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
completedStatusCode = 1;
|
|
149
|
+
completedTasks.push(...readCompletedTasks(options, executionId));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return { completedStatusCode, completedTasks };
|
|
154
|
+
}
|
|
155
|
+
function groupByTarget(tasks) {
|
|
156
|
+
const res = [];
|
|
157
|
+
tasks.forEach((t) => {
|
|
158
|
+
const r = res.find((rr) => rr.target === t.target && rr.configuration === t.configuration);
|
|
159
|
+
if (r) {
|
|
160
|
+
r.projects.push(t.projectName);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
res.push({
|
|
164
|
+
target: t.target,
|
|
165
|
+
projects: [t.projectName],
|
|
166
|
+
params: t.params,
|
|
167
|
+
configuration: t.configuration,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
return res;
|
|
172
|
+
}
|
|
173
|
+
function getAgentName() {
|
|
174
|
+
if (process.env.NX_AGENT_NAME !== undefined) {
|
|
175
|
+
return process.env.NX_AGENT_NAME;
|
|
176
|
+
}
|
|
177
|
+
else if (process.env.CIRCLECI !== undefined && process.env.CIRCLE_STAGE) {
|
|
178
|
+
return process.env.CIRCLE_STAGE;
|
|
179
|
+
}
|
|
180
|
+
else if (process.env.CIRCLECI !== undefined && process.env.CIRCLE_JOB) {
|
|
181
|
+
return process.env.CIRCLE_JOB;
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
return `Agent ${Math.floor(Math.random() * 100000)}`;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function createAgentLockfileAndSetUpListeners(api, options, agentName) {
|
|
188
|
+
const cacheDirectory = options.cacheDirectory || './node_modules/.cache/nx';
|
|
189
|
+
const lockFileDirectory = `${cacheDirectory}/lockfiles`;
|
|
190
|
+
const lockFilePath = `${lockFileDirectory}/${agentName}.lock`;
|
|
191
|
+
if (!(0, fs_1.existsSync)(lockFileDirectory)) {
|
|
192
|
+
(0, fs_1.mkdirSync)(lockFileDirectory, { recursive: true });
|
|
193
|
+
}
|
|
194
|
+
// Check for other agents' lockfiles and warn if exist
|
|
195
|
+
const lockFiles = (0, fs_1.readdirSync)(lockFileDirectory);
|
|
196
|
+
if (lockFiles.length) {
|
|
197
|
+
// Check to make sure the current agent name is not in use (only 1/100000 ^ 2 chance of this)
|
|
198
|
+
if (lockFiles.includes(`${agentName}.lock`)) {
|
|
199
|
+
output.error({
|
|
200
|
+
title: 'Duplicate Agent ID Detected',
|
|
201
|
+
bodyLines: [
|
|
202
|
+
'We have detected another agent with this ID running in this workspace. This should not happen.',
|
|
203
|
+
'',
|
|
204
|
+
'End all currently running agents, run "npx nx-cloud clean-up-agents", and try again.',
|
|
205
|
+
],
|
|
206
|
+
});
|
|
207
|
+
process.exit(1);
|
|
208
|
+
}
|
|
209
|
+
output.warn({
|
|
210
|
+
title: 'Other Nx Cloud Agents Detected',
|
|
211
|
+
bodyLines: [
|
|
212
|
+
'We have detected other agents running in this workspace. This can cause unexpected behavior.',
|
|
213
|
+
'',
|
|
214
|
+
'This can also be a false positive caused by agents that did not shut down correctly.',
|
|
215
|
+
'If you believe this is the case, run "npx nx-cloud clean-up-agents".',
|
|
216
|
+
],
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
(0, fs_1.writeFileSync)(lockFilePath, '');
|
|
220
|
+
process.on('exit', (code) => {
|
|
221
|
+
cleanupAgentLockfile(lockFilePath, code);
|
|
222
|
+
});
|
|
223
|
+
process.on('SIGTERM', () => __awaiter(this, void 0, void 0, function* () {
|
|
224
|
+
yield api.completeRunGroupWithError('Agent was terminated via SIGTERM');
|
|
225
|
+
cleanupAgentLockfile(lockFilePath, 1);
|
|
226
|
+
}));
|
|
227
|
+
process.on('SIGINT', () => __awaiter(this, void 0, void 0, function* () {
|
|
228
|
+
yield api.completeRunGroupWithError('Agent was terminated via SIGINT');
|
|
229
|
+
cleanupAgentLockfile(lockFilePath, 1);
|
|
230
|
+
}));
|
|
231
|
+
}
|
|
232
|
+
function cleanupAgentLockfile(lockFilePath, code) {
|
|
233
|
+
if ((0, fs_1.existsSync)(lockFilePath)) {
|
|
234
|
+
(0, fs_1.unlinkSync)(lockFilePath);
|
|
235
|
+
process.exit(code);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function startAgent() {
|
|
239
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
240
|
+
const runGroup = (0, environment_1.getRunGroup)();
|
|
241
|
+
if (!runGroup) {
|
|
242
|
+
(0, print_run_group_error_1.printRunGroupError)();
|
|
243
|
+
return process.exit(1);
|
|
244
|
+
}
|
|
245
|
+
output.note({
|
|
246
|
+
title: 'Starting an agent for running Nx tasks',
|
|
247
|
+
});
|
|
248
|
+
const defaultRunnerConfig = JSON.parse(stripJsonComments((0, fs_1.readFileSync)(`${workspaceRoot}/nx.json`).toString())).tasksRunnerOptions.default;
|
|
249
|
+
if (defaultRunnerConfig.runner !== '@nrwl/nx-cloud') {
|
|
250
|
+
(0, print_invalid_runner_error_1.printInvalidRunnerError)();
|
|
251
|
+
return process.exit(1);
|
|
252
|
+
}
|
|
253
|
+
const options = defaultRunnerConfig.options;
|
|
254
|
+
const agentName = getAgentName();
|
|
255
|
+
const api = new distributed_agent_api_1.DistributedAgentApi(options, runGroup, agentName);
|
|
256
|
+
createAgentLockfileAndSetUpListeners(api, options, agentName);
|
|
257
|
+
return executeTasks(options, api)
|
|
258
|
+
.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
259
|
+
yield (0, metric_logger_1.submitRunMetrics)(options);
|
|
260
|
+
return res;
|
|
261
|
+
}))
|
|
262
|
+
.catch((e) => __awaiter(this, void 0, void 0, function* () {
|
|
263
|
+
yield api.completeRunGroupWithError(`Critical Error in Agent: "${e.message}"`);
|
|
264
|
+
throw e;
|
|
265
|
+
}));
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
exports.startAgent = startAgent;
|
|
269
|
+
//# sourceMappingURL=distributed-agent.impl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"distributed-agent.impl.js","sourceRoot":"","sources":["../../../../../../../../libs/nx-packages/nx-cloud/lib/core/runners/distributed-agent/distributed-agent.impl.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAAyC;AACzC,2BAOY;AACZ,yDAAyD;AACzD,sGAAgG;AAChG,gEAKwC;AACxC,oEAAoE;AACpE,sDAAmD;AACnD,6EAAuE;AAOvE,mEAA8D;
|
|
1
|
+
{"version":3,"file":"distributed-agent.impl.js","sourceRoot":"","sources":["../../../../../../../../libs/nx-packages/nx-cloud/lib/core/runners/distributed-agent/distributed-agent.impl.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAAyC;AACzC,2BAOY;AACZ,yDAAyD;AACzD,sGAAgG;AAChG,gEAKwC;AACxC,oEAAoE;AACpE,sDAAmD;AACnD,6EAAuE;AAOvE,mEAA8D;AAC9D,uFAAiF;AAEjF,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,+BAA+B,CAAC,CAAC;AAE3E,SAAe,YAAY,CACzB,OAA+B,EAC/B,GAAwB;;QAExB,IAAI,mBAAmB,GAAG,CAAC,CAAC;QAC5B,IAAI,WAAW,GAA4B,IAAI,CAAC;QAChD,MAAM,2BAA2B,GAAG,IAAA,4DAA2B,EAAC;YAC9D,KAAK,EAAE,kCACL,iCAAmB,GAAG,IACxB,UAAU;YACV,OAAO,EAAE,iCAAmB;SAC7B,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,eAAM,EAAE,CAAC;QAE5B,IAAI,cAAc,GAAG,EAAwC,CAAC;QAE9D,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;QAC7B,IAAI,gBAAgB,GAAG,KAAK,CAAC;QAE7B,OAAO,IAAI,EAAE;YACX,IAAI,6BAAe,EAAE;gBACnB,MAAM,CAAC,IAAI,CAAC;oBACV,KAAK,EAAE,mBAAmB;iBAC3B,CAAC,CAAC;aACJ;YAED,WAAY,GAAG,MAAM,GAAG,CAAC,KAAK,CAC5B,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC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wC;SAChD,CAAC,CAAC;QAEH,MAAM,mBAAmB,GAAG,IAAI,CAAC,KAAK,CACpC,iBAAiB,CAAC,IAAA,iBAAY,EAAC,GAAG,aAAa,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,CACvE,CAAC,kBAAkB,CAAC,OAAO,CAAC;QAE7B,IAAI,mBAAmB,CAAC,MAAM,KAAK,gBAAgB,EAAE;YACnD,IAAA,oDAAuB,GAAE,CAAC;YAC1B,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACxB;QAED,MAAM,OAAO,GAAG,mBAAmB,CAAC,OAAO,CAAC;QAE5C,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;QACjC,MAAM,GAAG,GAAG,IAAI,2CAAmB,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;QAElE,oCAAoC,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;QAE9D,OAAO,YAAY,CAAC,OAAO,EAAE,GAAG,CAAC;aAC9B,IAAI,CAAC,CAAO,GAAG,EAAE,EAAE;YAClB,MAAM,IAAA,gCAAgB,EAAC,OAAO,CAAC,CAAC;YAChC,OAAO,GAAG,CAAC;QACb,CAAC,CAAA,CAAC;aACD,KAAK,CAAC,CAAO,CAAC,EAAE,EAAE;YACjB,MAAM,GAAG,CAAC,yBAAyB,CACjC,6BAA6B,CAAC,CAAC,OAAO,GAAG,CAC1C,CAAC;YACF,MAAM,CAAC,CAAC;QACV,CAAC,CAAA,CAAC,CAAC;IACP,CAAC;CAAA;AAtCD,gCAsCC"}
|
|
@@ -1 +1,143 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createStartRequest = exports.DistributedExecutionApi = void 0;
|
|
13
|
+
const axios_1 = require("../../../utilities/axios");
|
|
14
|
+
const environment_1 = require("../../../utilities/environment");
|
|
15
|
+
const metric_logger_1 = require("../../../utilities/metric-logger");
|
|
16
|
+
const serializer_overrides_1 = require("../../../utilities/serializer-overrides");
|
|
17
|
+
const { output } = require('../../../utilities/nx-imports');
|
|
18
|
+
class DistributedExecutionApi {
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options);
|
|
21
|
+
}
|
|
22
|
+
start(params) {
|
|
23
|
+
var _a;
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const recorder = (0, metric_logger_1.createMetricRecorder)('dteStart');
|
|
26
|
+
let resp;
|
|
27
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
28
|
+
output.note({
|
|
29
|
+
title: 'Starting a distributed execution',
|
|
30
|
+
bodyLines: [JSON.stringify(params, null, 2)],
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/start', params));
|
|
35
|
+
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
39
|
+
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
|
|
40
|
+
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
41
|
+
throw e;
|
|
42
|
+
}
|
|
43
|
+
if (!resp.data.enabled) {
|
|
44
|
+
throw new Error(`Workspace is disabled. Cannot perform distributed task executions.`);
|
|
45
|
+
}
|
|
46
|
+
if (resp.data.error) {
|
|
47
|
+
throw new Error(resp.data.error);
|
|
48
|
+
}
|
|
49
|
+
return resp.data.id;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
status(id) {
|
|
53
|
+
var _a;
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const recorder = (0, metric_logger_1.createMetricRecorder)('dteStatus');
|
|
56
|
+
try {
|
|
57
|
+
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/status', {
|
|
58
|
+
id,
|
|
59
|
+
}));
|
|
60
|
+
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
|
|
61
|
+
return resp.data;
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
65
|
+
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
|
|
66
|
+
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
67
|
+
output.error({
|
|
68
|
+
title: e.message,
|
|
69
|
+
});
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
completeRunGroupWithError(runGroup, error) {
|
|
75
|
+
var _a;
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const recorder = (0, metric_logger_1.createMetricRecorder)('completeRunGroup');
|
|
78
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
79
|
+
output.note({
|
|
80
|
+
title: 'Completing run group with an error',
|
|
81
|
+
bodyLines: [`runGroup: ${runGroup}`, `error: ${error}`],
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/complete-run-group', {
|
|
86
|
+
runGroup: runGroup,
|
|
87
|
+
criticalErrorMessage: error,
|
|
88
|
+
}), 3);
|
|
89
|
+
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
93
|
+
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
|
|
94
|
+
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.DistributedExecutionApi = DistributedExecutionApi;
|
|
100
|
+
function createStartRequest(runGroup, task, options) {
|
|
101
|
+
const tasksToExecute = task.map((arr) => {
|
|
102
|
+
return arr.map((t) => {
|
|
103
|
+
return {
|
|
104
|
+
taskId: t.id,
|
|
105
|
+
hash: t.hash,
|
|
106
|
+
projectName: t.target.project,
|
|
107
|
+
target: t.target.target,
|
|
108
|
+
configuration: t.target.configuration || null,
|
|
109
|
+
params: (0, serializer_overrides_1.serializeOverrides)(t),
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
const request = {
|
|
114
|
+
command: (0, environment_1.parseCommand)(),
|
|
115
|
+
branch: (0, environment_1.getBranch)(),
|
|
116
|
+
runGroup,
|
|
117
|
+
tasks: tasksToExecute,
|
|
118
|
+
maxParallel: calculateMaxParallel(options),
|
|
119
|
+
};
|
|
120
|
+
if (environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT) {
|
|
121
|
+
request.agentCount = environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT;
|
|
122
|
+
}
|
|
123
|
+
if (!environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_STOP_AGENTS_ON_FAILURE) {
|
|
124
|
+
request.stopAgentsOnFailure = false;
|
|
125
|
+
}
|
|
126
|
+
return request;
|
|
127
|
+
}
|
|
128
|
+
exports.createStartRequest = createStartRequest;
|
|
129
|
+
function calculateMaxParallel(options) {
|
|
130
|
+
if (options.parallel === 'false' || options.parallel === false) {
|
|
131
|
+
return 1;
|
|
132
|
+
}
|
|
133
|
+
else if (options.parallel === 'true' || options.parallel === true) {
|
|
134
|
+
return Number(options.maxParallel || 3);
|
|
135
|
+
}
|
|
136
|
+
else if (options.parallel === undefined) {
|
|
137
|
+
return options.maxParallel ? Number(options.maxParallel) : 3;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
return Number(options.parallel) || 3;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=distributed-execution.api.js.map
|