@nrwl/nx-cloud 14.2.0 → 14.2.1-beta.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.
- package/lib/core/api/error-reporter.api.js +36 -1
- package/lib/core/api/run-group.api.js +65 -1
- package/lib/core/file-storage/file-storage.js +38 -1
- package/lib/core/file-storage/file-storage.js.map +1 -1
- package/lib/core/runners/cloud-enabled/cloud-enabled-life-cycle.js +138 -1
- package/lib/core/runners/cloud-enabled/cloud-enabled.runner.js +169 -1
- package/lib/core/runners/cloud-enabled/cloud-remote-cache.js +113 -1
- package/lib/core/runners/cloud-enabled/cloud-run.api.js +166 -1
- package/lib/core/runners/distributed-agent/distributed-agent.api.js +79 -1
- package/lib/core/runners/distributed-agent/distributed-agent.impl.js +243 -1
- package/lib/core/runners/distributed-agent/distributed-agent.impl.js.map +1 -1
- package/lib/core/runners/distributed-execution/distributed-execution.api.js +131 -1
- package/lib/core/runners/distributed-execution/distributed-execution.runner.js +206 -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/create-no-new-messages-timeout.js +1 -1
- package/lib/utilities/create-no-new-messages-timeout.js.map +1 -1
- package/lib/utilities/environment.d.ts +1 -1
- package/lib/utilities/environment.js +5 -3
- package/lib/utilities/environment.js.map +1 -1
- package/package.json +1 -1
- package/project.json +36 -0
|
@@ -1 +1,243 @@
|
|
|
1
|
-
const a5_0x58fd=['We\x20have\x20detected\x20other\x20agents\x20running\x20in\x20this\x20workspace.\x20This\x20can\x20cause\x20unexpected\x20behavior.','completedStatusCode','random','../../../utilities/nx-imports','warn','__awaiter','Distributed\x20Execution\x20Terminated','inherit','.lock','Agent\x20','target','--configuration=','note','error','printRunGroupError','../../../utilities/metric-logger','assign','__esModule','projects','unlinkSync','retryDuring','We\x20have\x20detected\x20another\x20agent\x20with\x20this\x20ID\x20running\x20in\x20this\x20workspace.\x20This\x20should\x20not\x20happen.','catch','readFileSync','default','parse','apply','This\x20can\x20also\x20be\x20a\x20false\x20positive\x20caused\x20by\x20agents\x20that\x20did\x20not\x20shut\x20down\x20correctly.','cacheDirectory','maxParallel','SIGINT','join','env','existsSync','Error:','Critical\x20Error\x20in\x20Agent:\x20\x22','then','Waiter','getTime','taskId','reset','completed:\x20','push','options','execSync','../../error/print-run-group-error','maxParallel:\x20','mkdirSync','CIRCLE_STAGE','error:\x20','/nx.json','completed','tasks','completeRunGroupWithError','VERBOSE_LOGGING','message','child_process','Starting\x20an\x20agent\x20for\x20running\x20Nx\x20tasks','includes','/tasks-hashes-','toString','/lockfiles','throw','configuration','number\x20of\x20tasks:\x20','executionId','API\x20Response','./node_modules/.cache/nx','CIRCLECI','map','Executing:\x20\x27','submitRunMetrics','readdirSync','getRunGroup','Waiting...','forEach','wait','DistributedAgentApi','exit','CIRCLE_JOB','value','retryDuring:\x20','params','NX_AGENT_NAME','createNoNewMessagesTimeout','next','If\x20you\x20believe\x20this\x20is\x20the\x20case,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22.','writeFileSync','done','Fetching\x20tasks...','find','../../../utilities/environment','Command\x20execution\x20failed\x20(distributed\x20task\x20execution:\x20','DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE','true','Duplicate\x20Agent\x20ID\x20Detected'];(function(_0xb83545,_0x58fdd5){const _0x538276=function(_0x938392){while(--_0x938392){_0xb83545['push'](_0xb83545['shift']());}};_0x538276(++_0x58fdd5);}(a5_0x58fd,0x94));const a5_0x5382=function(_0xb83545,_0x58fdd5){_0xb83545=_0xb83545-0x0;let _0x538276=a5_0x58fd[_0xb83545];return _0x538276;};'use strict';var __awaiter=this&&this[a5_0x5382('0x31')]||function(_0x353f47,_0xd84879,_0x149b4e,_0x44e0d9){function _0x443111(_0x3f0731){return _0x3f0731 instanceof _0x149b4e?_0x3f0731:new _0x149b4e(function(_0x37ad9b){_0x37ad9b(_0x3f0731);});}return new(_0x149b4e||(_0x149b4e=Promise))(function(_0x43034d,_0xac4f89){function _0x17d00b(_0x5c2562){try{_0x3c7e5e(_0x44e0d9[a5_0x5382('0x21')](_0x5c2562));}catch(_0x52b5ac){_0xac4f89(_0x52b5ac);}}function _0x59a149(_0x278714){try{_0x3c7e5e(_0x44e0d9[a5_0x5382('0xa')](_0x278714));}catch(_0xd731aa){_0xac4f89(_0xd731aa);}}function _0x3c7e5e(_0x483c35){_0x483c35[a5_0x5382('0x24')]?_0x43034d(_0x483c35[a5_0x5382('0x1c')]):_0x443111(_0x483c35[a5_0x5382('0x1c')])[a5_0x5382('0x50')](_0x17d00b,_0x59a149);}_0x3c7e5e((_0x44e0d9=_0x44e0d9[a5_0x5382('0x46')](_0x353f47,_0xd84879||[]))[a5_0x5382('0x21')]());});};Object['defineProperty'](exports,a5_0x5382('0x3d'),{'value':!![]});exports['startAgent']=void 0x0;const child_process_1=require(a5_0x5382('0x4'));const stripJsonComments=require('strip-json-comments');const distributed_agent_api_1=require('./distributed-agent.api');const waiter_1=require('../../../utilities/waiter');const environment_1=require(a5_0x5382('0x27'));const print_run_group_error_1=require(a5_0x5382('0x59'));const create_no_new_messages_timeout_1=require('../../../utilities/create-no-new-messages-timeout');const fs_1=require('fs');const metric_logger_1=require(a5_0x5382('0x3b'));const {output,workspaceRoot}=require(a5_0x5382('0x2f'));function executeTasks(_0x35983b,_0x1fcf17){return __awaiter(this,void 0x0,void 0x0,function*(){let _0x4a687c=0x0;let _0x477114=null;const _0x3150cc=(0x0,create_no_new_messages_timeout_1[a5_0x5382('0x20')])();const _0x4b49e0=new waiter_1[(a5_0x5382('0x51'))]();let _0x62b63f=[];const _0x5b9cb3=new Date();let _0x103b28=![];while(!![]){if(environment_1[a5_0x5382('0x2')]){output['note']({'title':a5_0x5382('0x25')});}_0x477114=yield _0x1fcf17[a5_0x5382('0x0')](_0x477114?_0x477114[a5_0x5382('0xd')]:null,_0x4a687c,_0x62b63f);if(environment_1[a5_0x5382('0x2')]){output['note']({'title':a5_0x5382('0xe'),'bodyLines':[a5_0x5382('0x55')+_0x477114[a5_0x5382('0x5f')],a5_0x5382('0x1d')+_0x477114[a5_0x5382('0x40')],'executionId:\x20'+_0x477114[a5_0x5382('0xd')],a5_0x5382('0xc')+_0x477114[a5_0x5382('0x0')]['length'],a5_0x5382('0x5d')+_0x477114['criticalErrorMessage'],a5_0x5382('0x5a')+_0x477114[a5_0x5382('0x49')]]});}if(_0x477114['criticalErrorMessage']){output['error']({'title':a5_0x5382('0x32'),'bodyLines':[a5_0x5382('0x4e'),_0x477114['criticalErrorMessage']]});process[a5_0x5382('0x1a')](0x0);}if((_0x477114===null||_0x477114===void 0x0?void 0x0:_0x477114[a5_0x5382('0x40')])&&(_0x477114===null||_0x477114===void 0x0?void 0x0:_0x477114[a5_0x5382('0x40')])!==0x0&&!_0x103b28&&new Date()[a5_0x5382('0x52')]()-_0x5b9cb3[a5_0x5382('0x52')]()>_0x477114['retryDuring']){yield _0x4b49e0[a5_0x5382('0x18')]();continue;}if(_0x477114[a5_0x5382('0x5f')])return;_0x3150cc(_0x477114[a5_0x5382('0x0')][a5_0x5382('0x11')](_0x5e61b7=>_0x5e61b7[a5_0x5382('0x53')])['join'](''));if(!_0x477114[a5_0x5382('0xd')]){if(environment_1[a5_0x5382('0x2')]){output[a5_0x5382('0x38')]({'title':a5_0x5382('0x16')});}yield _0x4b49e0[a5_0x5382('0x18')]();_0x4a687c=0x0;_0x62b63f=[];continue;}_0x4b49e0[a5_0x5382('0x54')]();_0x103b28=!![];const _0x5ce953=invokeTasksUsingRunMany(_0x35983b,_0x477114['executionId'],_0x477114['tasks'],_0x477114[a5_0x5382('0x49')]);_0x4a687c=_0x5ce953[a5_0x5382('0x2d')];_0x62b63f=_0x5ce953['completedTasks'];}});}function readCompletedTasks(_0x3cdd36,_0x25c607){const _0x411554=a5_0x5382('0x28')+_0x25c607+').\x20Tasks\x20hashes\x20haven\x27t\x20been\x20recorded.';let _0x48b63b;try{const _0x316071=_0x3cdd36['cacheDirectory']||a5_0x5382('0xf');const _0x46baa3=_0x316071+a5_0x5382('0x7')+_0x25c607;_0x48b63b=JSON[a5_0x5382('0x45')]((0x0,fs_1[a5_0x5382('0x43')])(_0x46baa3)[a5_0x5382('0x8')]());(0x0,fs_1['unlinkSync'])(_0x46baa3);}catch(_0x5e6168){throw new Error(_0x411554);}if(_0x48b63b['length']==0x0){throw new Error(_0x411554);}return _0x48b63b;}function invokeTasksUsingRunMany(_0x1b8372,_0x1be021,_0x1080c5,_0x44b906){let _0x1a1877=0x0;const _0x2c4116=[];for(const _0x2941b9 of groupByTarget(_0x1080c5)){const _0x299bcb=_0x2941b9[a5_0x5382('0xb')]?a5_0x5382('0x37')+_0x2941b9[a5_0x5382('0xb')]:'';const _0x33ce7e=_0x44b906>0x1?'\x20--parallel\x20--max-parallel='+_0x44b906:'';const _0x2c6e31='npx\x20nx\x20run-many\x20--target='+_0x2941b9[a5_0x5382('0x36')]+'\x20'+_0x299bcb+'\x20--projects='+_0x2941b9[a5_0x5382('0x3e')][a5_0x5382('0x4b')](',')+'\x20'+_0x2941b9['params']+_0x33ce7e;if(environment_1[a5_0x5382('0x2')]){output[a5_0x5382('0x38')]({'title':a5_0x5382('0x12')+_0x2c6e31+'\x27'});}try{(0x0,child_process_1[a5_0x5382('0x58')])(_0x2c6e31,{'stdio':[a5_0x5382('0x33'),a5_0x5382('0x33'),a5_0x5382('0x33')],'env':Object[a5_0x5382('0x3c')](Object[a5_0x5382('0x3c')]({},process[a5_0x5382('0x4c')]),{'NX_CACHE_FAILURES':a5_0x5382('0x2a'),'NX_CLOUD_DISTRIBUTED_EXECUTION_ID':_0x1be021})});}catch(_0xd73f2){if(_0xd73f2['status']===environment_1[a5_0x5382('0x29')]){throw _0xd73f2;}else{_0x1a1877=0x1;}}finally{_0x2c4116[a5_0x5382('0x56')](...readCompletedTasks(_0x1b8372,_0x1be021));}}return{'completedStatusCode':_0x1a1877,'completedTasks':_0x2c4116};}function groupByTarget(_0x361e57){const _0x2f8233=[];_0x361e57[a5_0x5382('0x17')](_0x321eeb=>{const _0x75fae2=_0x2f8233[a5_0x5382('0x26')](_0x496687=>_0x496687[a5_0x5382('0x36')]===_0x321eeb[a5_0x5382('0x36')]&&_0x496687[a5_0x5382('0xb')]===_0x321eeb['configuration']);if(_0x75fae2){_0x75fae2[a5_0x5382('0x3e')][a5_0x5382('0x56')](_0x321eeb['projectName']);}else{_0x2f8233['push']({'target':_0x321eeb[a5_0x5382('0x36')],'projects':[_0x321eeb['projectName']],'params':_0x321eeb[a5_0x5382('0x1e')],'configuration':_0x321eeb[a5_0x5382('0xb')]});}});return _0x2f8233;}function getAgentName(){if(process[a5_0x5382('0x4c')][a5_0x5382('0x1f')]!==undefined){return process[a5_0x5382('0x4c')]['NX_AGENT_NAME'];}else if(process['env'][a5_0x5382('0x10')]!==undefined&&process['env'][a5_0x5382('0x5c')]){return process['env']['CIRCLE_STAGE'];}else if(process[a5_0x5382('0x4c')][a5_0x5382('0x10')]!==undefined&&process[a5_0x5382('0x4c')][a5_0x5382('0x1b')]){return process[a5_0x5382('0x4c')][a5_0x5382('0x1b')];}else{return a5_0x5382('0x35')+Math['floor'](Math[a5_0x5382('0x2e')]()*0x186a0);}}function createAgentLockfile(_0x400541,_0x40dce0){const _0xf6cb3d=_0x400541[a5_0x5382('0x48')]||a5_0x5382('0xf');const _0x57226b=_0xf6cb3d+a5_0x5382('0x9');const _0x1b0628=_0x57226b+'/'+_0x40dce0+a5_0x5382('0x34');if(!(0x0,fs_1[a5_0x5382('0x4d')])(_0x57226b)){(0x0,fs_1[a5_0x5382('0x5b')])(_0x57226b,{'recursive':!![]});}const _0x541ef3=(0x0,fs_1[a5_0x5382('0x14')])(_0x57226b);if(_0x541ef3['length']){if(_0x541ef3[a5_0x5382('0x6')](_0x40dce0+'.lock')){output[a5_0x5382('0x39')]({'title':a5_0x5382('0x2b'),'bodyLines':[a5_0x5382('0x41'),'','End\x20all\x20currently\x20running\x20agents,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22,\x20and\x20try\x20again.']});process[a5_0x5382('0x1a')](0x1);}output[a5_0x5382('0x30')]({'title':'Other\x20Nx\x20Cloud\x20Agents\x20Detected','bodyLines':[a5_0x5382('0x2c'),'',a5_0x5382('0x47'),a5_0x5382('0x22')]});}(0x0,fs_1[a5_0x5382('0x23')])(_0x1b0628,'');process['on'](a5_0x5382('0x1a'),_0x4c58fa=>cleanupAgentLockfile(_0x1b0628,_0x4c58fa));process['on'](a5_0x5382('0x4a'),()=>cleanupAgentLockfile(_0x1b0628,0x0));}function cleanupAgentLockfile(_0x5d7da9,_0x1347cb){if((0x0,fs_1[a5_0x5382('0x4d')])(_0x5d7da9)){(0x0,fs_1[a5_0x5382('0x3f')])(_0x5d7da9);process[a5_0x5382('0x1a')](_0x1347cb);}}function startAgent(){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x4845ef=(0x0,environment_1[a5_0x5382('0x15')])();if(!_0x4845ef){(0x0,print_run_group_error_1[a5_0x5382('0x3a')])();return process[a5_0x5382('0x1a')](0x1);}output['note']({'title':a5_0x5382('0x5')});const _0x1a4a38=JSON['parse'](stripJsonComments((0x0,fs_1['readFileSync'])(workspaceRoot+a5_0x5382('0x5e'))[a5_0x5382('0x8')]()))['tasksRunnerOptions'][a5_0x5382('0x44')][a5_0x5382('0x57')];const _0x23e50c=getAgentName();createAgentLockfile(_0x1a4a38,_0x23e50c);const _0x584316=new distributed_agent_api_1[(a5_0x5382('0x19'))](_0x1a4a38,_0x4845ef,_0x23e50c);return executeTasks(_0x1a4a38,_0x584316)[a5_0x5382('0x50')](_0xa67e93=>__awaiter(this,void 0x0,void 0x0,function*(){yield(0x0,metric_logger_1[a5_0x5382('0x13')])(_0x1a4a38);return _0xa67e93;}))[a5_0x5382('0x42')](_0x4a0446=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x584316[a5_0x5382('0x1')](a5_0x5382('0x4f')+_0x4a0446[a5_0x5382('0x3')]+'\x22');throw _0x4a0446;}));});}exports['startAgent']=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_no_new_messages_timeout_1 = require("../../../utilities/create-no-new-messages-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 { output, workspaceRoot } = require('../../../utilities/nx-imports');
|
|
23
|
+
function executeTasks(options, api) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
let completedStatusCode = 0;
|
|
26
|
+
let apiResponse = null;
|
|
27
|
+
const failIfSameTasksAfterTimeout = (0, create_no_new_messages_timeout_1.createNoNewMessagesTimeout)();
|
|
28
|
+
const waiter = new waiter_1.Waiter();
|
|
29
|
+
let completedTasks = [];
|
|
30
|
+
const startTime = new Date();
|
|
31
|
+
let executedAnyTasks = false;
|
|
32
|
+
while (true) {
|
|
33
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
34
|
+
output.note({
|
|
35
|
+
title: 'Fetching tasks...',
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
apiResponse = yield api.tasks(apiResponse ? apiResponse.executionId : null, completedStatusCode, completedTasks);
|
|
39
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
40
|
+
output.note({
|
|
41
|
+
title: 'API Response',
|
|
42
|
+
bodyLines: [
|
|
43
|
+
`completed: ${apiResponse.completed}`,
|
|
44
|
+
`retryDuring: ${apiResponse.retryDuring}`,
|
|
45
|
+
`executionId: ${apiResponse.executionId}`,
|
|
46
|
+
`number of tasks: ${apiResponse.tasks.length}`,
|
|
47
|
+
`error: ${apiResponse.criticalErrorMessage}`,
|
|
48
|
+
`maxParallel: ${apiResponse.maxParallel}`,
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (apiResponse.criticalErrorMessage) {
|
|
53
|
+
output.error({
|
|
54
|
+
title: 'Distributed Execution Terminated',
|
|
55
|
+
bodyLines: ['Error:', apiResponse.criticalErrorMessage],
|
|
56
|
+
});
|
|
57
|
+
process.exit(0);
|
|
58
|
+
}
|
|
59
|
+
// run group is completed but it might be a rerun
|
|
60
|
+
// we will try several times before going further and
|
|
61
|
+
// completed the response
|
|
62
|
+
// we only do it if we haven't executed any tasks
|
|
63
|
+
if ((apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.retryDuring) &&
|
|
64
|
+
(apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.retryDuring) !== 0 &&
|
|
65
|
+
!executedAnyTasks &&
|
|
66
|
+
new Date().getTime() - startTime.getTime() > apiResponse.retryDuring) {
|
|
67
|
+
yield waiter.wait();
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (apiResponse.completed)
|
|
71
|
+
return;
|
|
72
|
+
failIfSameTasksAfterTimeout(apiResponse.tasks.map((t) => t.taskId).join(''));
|
|
73
|
+
if (!apiResponse.executionId) {
|
|
74
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
75
|
+
output.note({
|
|
76
|
+
title: 'Waiting...',
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
yield waiter.wait();
|
|
80
|
+
completedStatusCode = 0;
|
|
81
|
+
completedTasks = [];
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
waiter.reset();
|
|
85
|
+
executedAnyTasks = true;
|
|
86
|
+
const r = invokeTasksUsingRunMany(options, apiResponse.executionId, apiResponse.tasks, apiResponse.maxParallel);
|
|
87
|
+
completedStatusCode = r.completedStatusCode;
|
|
88
|
+
completedTasks = r.completedTasks;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function readCompletedTasks(options, distributedExecutionId) {
|
|
93
|
+
const errorMessage = `Command execution failed (distributed task execution: ${distributedExecutionId}). Tasks hashes haven\'t been recorded.`;
|
|
94
|
+
let completedTasks;
|
|
95
|
+
try {
|
|
96
|
+
const cacheDirectory = options.cacheDirectory || './node_modules/.cache/nx';
|
|
97
|
+
const taskHashesFile = `${cacheDirectory}/tasks-hashes-${distributedExecutionId}`;
|
|
98
|
+
completedTasks = JSON.parse((0, fs_1.readFileSync)(taskHashesFile).toString());
|
|
99
|
+
// remove it such that if the next command crashes we don't read an obsolete file
|
|
100
|
+
(0, fs_1.unlinkSync)(taskHashesFile);
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
throw new Error(errorMessage);
|
|
104
|
+
}
|
|
105
|
+
if (completedTasks.length == 0) {
|
|
106
|
+
throw new Error(errorMessage);
|
|
107
|
+
}
|
|
108
|
+
return completedTasks;
|
|
109
|
+
}
|
|
110
|
+
function invokeTasksUsingRunMany(options, executionId, tasks, maxParallel) {
|
|
111
|
+
let completedStatusCode = 0;
|
|
112
|
+
const completedTasks = [];
|
|
113
|
+
for (const g of groupByTarget(tasks)) {
|
|
114
|
+
const config = g.configuration ? `--configuration=${g.configuration}` : ``;
|
|
115
|
+
const parallel = maxParallel > 1 ? ` --parallel --max-parallel=${maxParallel}` : ``;
|
|
116
|
+
// TODO use pnpx or yarn when needed
|
|
117
|
+
const command = `npx nx run-many --target=${g.target} ${config} --projects=${g.projects.join(',')} ${g.params}${parallel}`;
|
|
118
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
119
|
+
output.note({
|
|
120
|
+
title: `Executing: '${command}'`,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
(0, child_process_1.execSync)(command, {
|
|
125
|
+
stdio: ['inherit', 'inherit', 'inherit'],
|
|
126
|
+
env: Object.assign(Object.assign({}, process.env), { NX_CACHE_FAILURES: 'true', NX_CLOUD_DISTRIBUTED_EXECUTION_ID: executionId }),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
if (e.status === environment_1.DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE) {
|
|
131
|
+
throw e;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
completedStatusCode = 1;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
completedTasks.push(...readCompletedTasks(options, executionId));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return { completedStatusCode, completedTasks };
|
|
142
|
+
}
|
|
143
|
+
function groupByTarget(tasks) {
|
|
144
|
+
const res = [];
|
|
145
|
+
tasks.forEach((t) => {
|
|
146
|
+
const r = res.find((rr) => rr.target === t.target && rr.configuration === t.configuration);
|
|
147
|
+
if (r) {
|
|
148
|
+
r.projects.push(t.projectName);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
res.push({
|
|
152
|
+
target: t.target,
|
|
153
|
+
projects: [t.projectName],
|
|
154
|
+
params: t.params,
|
|
155
|
+
configuration: t.configuration,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
return res;
|
|
160
|
+
}
|
|
161
|
+
function getAgentName() {
|
|
162
|
+
if (process.env.NX_AGENT_NAME !== undefined) {
|
|
163
|
+
return process.env.NX_AGENT_NAME;
|
|
164
|
+
}
|
|
165
|
+
else if (process.env.CIRCLECI !== undefined && process.env.CIRCLE_STAGE) {
|
|
166
|
+
return process.env.CIRCLE_STAGE;
|
|
167
|
+
}
|
|
168
|
+
else if (process.env.CIRCLECI !== undefined && process.env.CIRCLE_JOB) {
|
|
169
|
+
return process.env.CIRCLE_JOB;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
return `Agent ${Math.floor(Math.random() * 100000)}`;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function createAgentLockfile(options, agentName) {
|
|
176
|
+
const cacheDirectory = options.cacheDirectory || './node_modules/.cache/nx';
|
|
177
|
+
const lockFileDirectory = `${cacheDirectory}/lockfiles`;
|
|
178
|
+
const lockFilePath = `${lockFileDirectory}/${agentName}.lock`;
|
|
179
|
+
if (!(0, fs_1.existsSync)(lockFileDirectory)) {
|
|
180
|
+
(0, fs_1.mkdirSync)(lockFileDirectory, { recursive: true });
|
|
181
|
+
}
|
|
182
|
+
// Check for other agents' lockfiles and warn if exist
|
|
183
|
+
const lockFiles = (0, fs_1.readdirSync)(lockFileDirectory);
|
|
184
|
+
if (lockFiles.length) {
|
|
185
|
+
// Check to make sure the current agent name is not in use (only 1/100000 ^ 2 chance of this)
|
|
186
|
+
if (lockFiles.includes(`${agentName}.lock`)) {
|
|
187
|
+
output.error({
|
|
188
|
+
title: 'Duplicate Agent ID Detected',
|
|
189
|
+
bodyLines: [
|
|
190
|
+
'We have detected another agent with this ID running in this workspace. This should not happen.',
|
|
191
|
+
'',
|
|
192
|
+
'End all currently running agents, run "npx nx-cloud clean-up-agents", and try again.',
|
|
193
|
+
],
|
|
194
|
+
});
|
|
195
|
+
process.exit(1);
|
|
196
|
+
}
|
|
197
|
+
output.warn({
|
|
198
|
+
title: 'Other Nx Cloud Agents Detected',
|
|
199
|
+
bodyLines: [
|
|
200
|
+
'We have detected other agents running in this workspace. This can cause unexpected behavior.',
|
|
201
|
+
'',
|
|
202
|
+
'This can also be a false positive caused by agents that did not shut down correctly.',
|
|
203
|
+
'If you believe this is the case, run "npx nx-cloud clean-up-agents".',
|
|
204
|
+
],
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
(0, fs_1.writeFileSync)(lockFilePath, '');
|
|
208
|
+
process.on('exit', (code) => cleanupAgentLockfile(lockFilePath, code));
|
|
209
|
+
process.on('SIGINT', () => cleanupAgentLockfile(lockFilePath, 0));
|
|
210
|
+
}
|
|
211
|
+
function cleanupAgentLockfile(lockFilePath, code) {
|
|
212
|
+
if ((0, fs_1.existsSync)(lockFilePath)) {
|
|
213
|
+
(0, fs_1.unlinkSync)(lockFilePath);
|
|
214
|
+
process.exit(code);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function startAgent() {
|
|
218
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
219
|
+
const runGroup = (0, environment_1.getRunGroup)();
|
|
220
|
+
if (!runGroup) {
|
|
221
|
+
(0, print_run_group_error_1.printRunGroupError)();
|
|
222
|
+
return process.exit(1);
|
|
223
|
+
}
|
|
224
|
+
output.note({
|
|
225
|
+
title: 'Starting an agent for running Nx tasks',
|
|
226
|
+
});
|
|
227
|
+
const options = JSON.parse(stripJsonComments((0, fs_1.readFileSync)(`${workspaceRoot}/nx.json`).toString())).tasksRunnerOptions.default.options;
|
|
228
|
+
const agentName = getAgentName();
|
|
229
|
+
createAgentLockfile(options, agentName);
|
|
230
|
+
const api = new distributed_agent_api_1.DistributedAgentApi(options, runGroup, agentName);
|
|
231
|
+
return executeTasks(options, api)
|
|
232
|
+
.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
233
|
+
yield (0, metric_logger_1.submitRunMetrics)(options);
|
|
234
|
+
return res;
|
|
235
|
+
}))
|
|
236
|
+
.catch((e) => __awaiter(this, void 0, void 0, function* () {
|
|
237
|
+
yield api.completeRunGroupWithError(`Critical Error in Agent: "${e.message}"`);
|
|
238
|
+
throw e;
|
|
239
|
+
}));
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
exports.startAgent = startAgent;
|
|
243
|
+
//# 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,
|
|
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,sGAA+F;AAC/F,gEAIwC;AACxC,oEAAoE;AACpE,sDAAmD;AACnD,6EAAuE;AAOvE,mEAA8D;AAE9D,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,2DAA0B,GAAE,CAAC;QACjE,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;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C,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;AA/BD,gCA+BC"}
|
|
@@ -1 +1,131 @@
|
|
|
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, unparse } = 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
|
+
try {
|
|
28
|
+
resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/start', params));
|
|
29
|
+
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
33
|
+
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
|
|
34
|
+
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
35
|
+
throw e;
|
|
36
|
+
}
|
|
37
|
+
if (!resp.data.enabled) {
|
|
38
|
+
throw new Error(`Workspace is disabled. Cannot perform distributed task executions.`);
|
|
39
|
+
}
|
|
40
|
+
if (resp.data.error) {
|
|
41
|
+
throw new Error(resp.data.error);
|
|
42
|
+
}
|
|
43
|
+
return resp.data.id;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
status(id) {
|
|
47
|
+
var _a;
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const recorder = (0, metric_logger_1.createMetricRecorder)('dteStatus');
|
|
50
|
+
try {
|
|
51
|
+
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/status', {
|
|
52
|
+
id,
|
|
53
|
+
}));
|
|
54
|
+
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
|
|
55
|
+
return resp.data;
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
59
|
+
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
|
|
60
|
+
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
61
|
+
output.error({
|
|
62
|
+
title: e.message,
|
|
63
|
+
});
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
completeRunGroupWithError(runGroup, error) {
|
|
69
|
+
var _a;
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const recorder = (0, metric_logger_1.createMetricRecorder)('completeRunGroup');
|
|
72
|
+
try {
|
|
73
|
+
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/complete-run-group', {
|
|
74
|
+
runGroup: runGroup,
|
|
75
|
+
criticalErrorMessage: error,
|
|
76
|
+
}), 3);
|
|
77
|
+
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
81
|
+
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
|
|
82
|
+
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.DistributedExecutionApi = DistributedExecutionApi;
|
|
88
|
+
function createStartRequest(runGroup, task, options) {
|
|
89
|
+
const tasksToExecute = task.map((arr) => {
|
|
90
|
+
return arr.map((t) => {
|
|
91
|
+
return {
|
|
92
|
+
taskId: t.id,
|
|
93
|
+
hash: t.hash,
|
|
94
|
+
projectName: t.target.project,
|
|
95
|
+
target: t.target.target,
|
|
96
|
+
configuration: t.target.configuration || null,
|
|
97
|
+
params: (0, serializer_overrides_1.serializeOverrides)(t),
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
const request = {
|
|
102
|
+
command: (0, environment_1.parseCommand)(),
|
|
103
|
+
branch: (0, environment_1.getBranch)(),
|
|
104
|
+
runGroup,
|
|
105
|
+
tasks: tasksToExecute,
|
|
106
|
+
maxParallel: calculateMaxParallel(options),
|
|
107
|
+
};
|
|
108
|
+
if (environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT) {
|
|
109
|
+
request.agentCount = environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT;
|
|
110
|
+
}
|
|
111
|
+
if (!environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_STOP_AGENTS_ON_FAILURE) {
|
|
112
|
+
request.stopAgentsOnFailure = false;
|
|
113
|
+
}
|
|
114
|
+
return request;
|
|
115
|
+
}
|
|
116
|
+
exports.createStartRequest = createStartRequest;
|
|
117
|
+
function calculateMaxParallel(options) {
|
|
118
|
+
if (options.parallel === 'false' || options.parallel === false) {
|
|
119
|
+
return 1;
|
|
120
|
+
}
|
|
121
|
+
else if (options.parallel === 'true' || options.parallel === true) {
|
|
122
|
+
return Number(options.maxParallel || 3);
|
|
123
|
+
}
|
|
124
|
+
else if (options.parallel === undefined) {
|
|
125
|
+
return options.maxParallel ? Number(options.maxParallel) : 3;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
return Number(options.parallel) || 3;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=distributed-execution.api.js.map
|