@nrwl/nx-cloud 14.0.5 → 14.0.6-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.
@@ -1 +1,240 @@
1
- const a5_0x1e02=['../../error/print-run-group-error','random','VERBOSE_LOGGING','projectName','error:\x20','map','This\x20can\x20also\x20be\x20a\x20false\x20positive\x20caused\x20by\x20agents\x20that\x20did\x20not\x20shut\x20down\x20correctly.','SIGINT','.lock','completed:\x20','Executing:\x20\x27',').\x20Tasks\x20hashes\x20haven\x27t\x20been\x20recorded.','then','exit','printRunGroupError','taskId','completeRunGroupWithError','assign','length','tasks','NX_AGENT_NAME','retryDuring','API\x20Response','DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE','maxParallel','message','toString','next','Agent\x20','submitRunMetrics','status','./node_modules/.cache/nx','Other\x20Nx\x20Cloud\x20Agents\x20Detected','join','projects','catch','configuration','maxParallel:\x20','../../../utilities/metric-logger','existsSync','We\x20have\x20detected\x20another\x20agent\x20with\x20this\x20ID\x20running\x20in\x20this\x20workspace.\x20This\x20should\x20not\x20happen.','unlinkSync','./distributed-agent.api','includes','/lockfiles','find','Fetching\x20tasks...','Command\x20execution\x20failed\x20(distributed\x20task\x20execution:\x20','executionId','value','Starting\x20an\x20agent\x20for\x20running\x20Nx\x20tasks','CIRCLE_STAGE','retryDuring:\x20','../../../utilities/environment','mkdirSync','../../../utilities/waiter','../../../utilities/create-no-new-messages-timeout','createNoNewMessagesTimeout','inherit','reset','note','criticalErrorMessage','completed','Critical\x20Error\x20in\x20Agent:\x20\x22','writeFileSync','defineProperty','execSync','completedTasks','\x20--projects=','../../../utilities/nx-imports','done','\x20--parallel\x20--max-parallel=','__awaiter','Error:','npx\x20nx\x20run-many\x20--target=','/tasks-hashes-','readFileSync','startAgent','executionId:\x20','apply','End\x20all\x20currently\x20running\x20agents,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22,\x20and\x20try\x20again.','parse','child_process','wait','push','params','getTime','env','target','warn','Waiting...','number\x20of\x20tasks:\x20','cacheDirectory','error'];(function(_0x8b778f,_0x1e0222){const _0x561599=function(_0x31dfd3){while(--_0x31dfd3){_0x8b778f['push'](_0x8b778f['shift']());}};_0x561599(++_0x1e0222);}(a5_0x1e02,0x88));const a5_0x5615=function(_0x8b778f,_0x1e0222){_0x8b778f=_0x8b778f-0x0;let _0x561599=a5_0x1e02[_0x8b778f];return _0x561599;};'use strict';var __awaiter=this&&this[a5_0x5615('0x1e')]||function(_0x3ef85b,_0x3865ba,_0x105261,_0x5d48a6){function _0x1c05c5(_0x353019){return _0x353019 instanceof _0x105261?_0x353019:new _0x105261(function(_0x148109){_0x148109(_0x353019);});}return new(_0x105261||(_0x105261=Promise))(function(_0x527195,_0x2b212f){function _0x4f95df(_0x51b357){try{_0x328570(_0x5d48a6[a5_0x5615('0x4f')](_0x51b357));}catch(_0x39ee25){_0x2b212f(_0x39ee25);}}function _0xf1808c(_0x1249cc){try{_0x328570(_0x5d48a6['throw'](_0x1249cc));}catch(_0x568b15){_0x2b212f(_0x568b15);}}function _0x328570(_0x33e835){_0x33e835[a5_0x5615('0x1c')]?_0x527195(_0x33e835[a5_0x5615('0x7')]):_0x1c05c5(_0x33e835[a5_0x5615('0x7')])[a5_0x5615('0x40')](_0x4f95df,_0xf1808c);}_0x328570((_0x5d48a6=_0x5d48a6[a5_0x5615('0x25')](_0x3ef85b,_0x3865ba||[]))[a5_0x5615('0x4f')]());});};Object[a5_0x5615('0x17')](exports,'__esModule',{'value':!![]});exports[a5_0x5615('0x23')]=void 0x0;const child_process_1=require(a5_0x5615('0x28'));const stripJsonComments=require('strip-json-comments');const distributed_agent_api_1=require(a5_0x5615('0x0'));const waiter_1=require(a5_0x5615('0xd'));const environment_1=require(a5_0x5615('0xb'));const print_run_group_error_1=require(a5_0x5615('0x34'));const create_no_new_messages_timeout_1=require(a5_0x5615('0xe'));const fs_1=require('fs');const metric_logger_1=require(a5_0x5615('0x5a'));const {output,workspaceRoot}=require(a5_0x5615('0x1b'));function executeTasks(_0x15214f,_0x3ab6a4){return __awaiter(this,void 0x0,void 0x0,function*(){let _0x2fc04b=0x0;let _0x145b0c=null;const _0x2fd06a=(0x0,create_no_new_messages_timeout_1[a5_0x5615('0xf')])();const _0x14b7b3=new waiter_1['Waiter']();let _0x35121e=[];const _0x38db62=new Date();let _0xf775c8=![];while(!![]){if(environment_1[a5_0x5615('0x36')]){output[a5_0x5615('0x12')]({'title':a5_0x5615('0x4')});}_0x145b0c=yield _0x3ab6a4[a5_0x5615('0x47')](_0x145b0c?_0x145b0c[a5_0x5615('0x6')]:null,_0x2fc04b,_0x35121e);if(environment_1[a5_0x5615('0x36')]){output[a5_0x5615('0x12')]({'title':a5_0x5615('0x4a'),'bodyLines':[a5_0x5615('0x3d')+_0x145b0c[a5_0x5615('0x14')],a5_0x5615('0xa')+_0x145b0c['retryDuring'],a5_0x5615('0x24')+_0x145b0c[a5_0x5615('0x6')],a5_0x5615('0x31')+_0x145b0c['tasks'][a5_0x5615('0x46')],a5_0x5615('0x38')+_0x145b0c[a5_0x5615('0x13')],a5_0x5615('0x59')+_0x145b0c['maxParallel']]});}if(_0x145b0c[a5_0x5615('0x13')]){output[a5_0x5615('0x33')]({'title':'Distributed\x20Execution\x20Terminated','bodyLines':[a5_0x5615('0x1f'),_0x145b0c['criticalErrorMessage']]});process[a5_0x5615('0x41')](0x0);}if((_0x145b0c===null||_0x145b0c===void 0x0?void 0x0:_0x145b0c['retryDuring'])&&(_0x145b0c===null||_0x145b0c===void 0x0?void 0x0:_0x145b0c['retryDuring'])!==0x0&&!_0xf775c8&&new Date()[a5_0x5615('0x2c')]()-_0x38db62['getTime']()>_0x145b0c[a5_0x5615('0x49')]){yield _0x14b7b3[a5_0x5615('0x29')]();continue;}if(_0x145b0c['completed'])return;_0x2fd06a(_0x145b0c['tasks'][a5_0x5615('0x39')](_0x20e449=>_0x20e449[a5_0x5615('0x43')])[a5_0x5615('0x55')](''));if(!_0x145b0c[a5_0x5615('0x6')]){if(environment_1['VERBOSE_LOGGING']){output['note']({'title':a5_0x5615('0x30')});}yield _0x14b7b3[a5_0x5615('0x29')]();_0x2fc04b=0x0;_0x35121e=[];continue;}_0x14b7b3[a5_0x5615('0x11')]();_0xf775c8=!![];const _0x3bae23=invokeTasksUsingRunMany(_0x15214f,_0x145b0c['executionId'],_0x145b0c[a5_0x5615('0x47')],_0x145b0c[a5_0x5615('0x4c')]);_0x2fc04b=_0x3bae23['completedStatusCode'];_0x35121e=_0x3bae23[a5_0x5615('0x19')];}});}function readCompletedTasks(_0x12924b,_0x1fef34){const _0x1313a0=a5_0x5615('0x5')+_0x1fef34+a5_0x5615('0x3f');let _0x17e87e;try{const _0x536b9c=_0x12924b[a5_0x5615('0x32')]||a5_0x5615('0x53');const _0x4ce3a7=_0x536b9c+a5_0x5615('0x21')+_0x1fef34;_0x17e87e=JSON[a5_0x5615('0x27')]((0x0,fs_1[a5_0x5615('0x22')])(_0x4ce3a7)[a5_0x5615('0x4e')]());(0x0,fs_1[a5_0x5615('0x5d')])(_0x4ce3a7);}catch(_0xf1ef69){throw new Error(_0x1313a0);}if(_0x17e87e[a5_0x5615('0x46')]==0x0){throw new Error(_0x1313a0);}return _0x17e87e;}function invokeTasksUsingRunMany(_0x3df89d,_0x8f9f64,_0x5ec450,_0x30909b){let _0x2e933e=0x0;const _0x3d25a8=[];for(const _0x1025de of groupByTarget(_0x5ec450)){const _0x4c7221=_0x1025de[a5_0x5615('0x58')]?'--configuration='+_0x1025de[a5_0x5615('0x58')]:'';const _0x20e823=_0x30909b>0x1?a5_0x5615('0x1d')+_0x30909b:'';const _0x479bb7=a5_0x5615('0x20')+_0x1025de[a5_0x5615('0x2e')]+'\x20'+_0x4c7221+a5_0x5615('0x1a')+_0x1025de[a5_0x5615('0x56')][a5_0x5615('0x55')](',')+'\x20'+_0x1025de[a5_0x5615('0x2b')]+_0x20e823;if(environment_1[a5_0x5615('0x36')]){output['note']({'title':a5_0x5615('0x3e')+_0x479bb7+'\x27'});}try{(0x0,child_process_1[a5_0x5615('0x18')])(_0x479bb7,{'stdio':[a5_0x5615('0x10'),a5_0x5615('0x10'),a5_0x5615('0x10')],'env':Object[a5_0x5615('0x45')](Object[a5_0x5615('0x45')]({},process[a5_0x5615('0x2d')]),{'NX_CACHE_FAILURES':'true','NX_CLOUD_DISTRIBUTED_EXECUTION_ID':_0x8f9f64})});}catch(_0x52a377){if(_0x52a377[a5_0x5615('0x52')]===environment_1[a5_0x5615('0x4b')]){throw _0x52a377;}else{_0x2e933e=0x1;}}finally{_0x3d25a8[a5_0x5615('0x2a')](...readCompletedTasks(_0x3df89d,_0x8f9f64));}}return{'completedStatusCode':_0x2e933e,'completedTasks':_0x3d25a8};}function groupByTarget(_0x40e027){const _0x3fa765=[];_0x40e027['forEach'](_0x2c2686=>{const _0x2f1a0f=_0x3fa765[a5_0x5615('0x3')](_0xa146af=>_0xa146af[a5_0x5615('0x2e')]===_0x2c2686[a5_0x5615('0x2e')]&&_0xa146af[a5_0x5615('0x58')]===_0x2c2686['configuration']);if(_0x2f1a0f){_0x2f1a0f[a5_0x5615('0x56')][a5_0x5615('0x2a')](_0x2c2686[a5_0x5615('0x37')]);}else{_0x3fa765[a5_0x5615('0x2a')]({'target':_0x2c2686[a5_0x5615('0x2e')],'projects':[_0x2c2686['projectName']],'params':_0x2c2686['params'],'configuration':_0x2c2686[a5_0x5615('0x58')]});}});return _0x3fa765;}function getAgentName(){if(process[a5_0x5615('0x2d')][a5_0x5615('0x48')]!==undefined){return process[a5_0x5615('0x2d')][a5_0x5615('0x48')];}else if(process['env']['CIRCLECI']!==undefined){return process[a5_0x5615('0x2d')][a5_0x5615('0x9')];}else{return a5_0x5615('0x50')+Math['floor'](Math[a5_0x5615('0x35')]()*0x186a0);}}function createAgentLockfile(_0x4613b7,_0xdb6e63){const _0x49a195=_0x4613b7[a5_0x5615('0x32')]||'./node_modules/.cache/nx';const _0x4ed5ea=_0x49a195+a5_0x5615('0x2');const _0x5f3f12=_0x4ed5ea+'/'+_0xdb6e63+'.lock';if(!(0x0,fs_1['existsSync'])(_0x4ed5ea)){(0x0,fs_1[a5_0x5615('0xc')])(_0x4ed5ea,{'recursive':!![]});}const _0x2bcbca=(0x0,fs_1['readdirSync'])(_0x4ed5ea);if(_0x2bcbca['length']){if(_0x2bcbca[a5_0x5615('0x1')](_0xdb6e63+a5_0x5615('0x3c'))){output[a5_0x5615('0x33')]({'title':'Duplicate\x20Agent\x20ID\x20Detected','bodyLines':[a5_0x5615('0x5c'),'',a5_0x5615('0x26')]});process[a5_0x5615('0x41')](0x1);}output[a5_0x5615('0x2f')]({'title':a5_0x5615('0x54'),'bodyLines':['We\x20have\x20detected\x20other\x20agents\x20running\x20in\x20this\x20workspace.\x20This\x20can\x20cause\x20unexpected\x20behavior.','',a5_0x5615('0x3a'),'If\x20you\x20believe\x20this\x20is\x20the\x20case,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22.']});}(0x0,fs_1[a5_0x5615('0x16')])(_0x5f3f12,'');process['on'](a5_0x5615('0x41'),_0x8cc447=>cleanupAgentLockfile(_0x5f3f12,_0x8cc447));process['on'](a5_0x5615('0x3b'),()=>cleanupAgentLockfile(_0x5f3f12,0x0));}function cleanupAgentLockfile(_0x359fd8,_0x530b53){if((0x0,fs_1[a5_0x5615('0x5b')])(_0x359fd8)){(0x0,fs_1[a5_0x5615('0x5d')])(_0x359fd8);process[a5_0x5615('0x41')](_0x530b53);}}function startAgent(){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x8be062=(0x0,environment_1['getRunGroup'])();if(!_0x8be062){(0x0,print_run_group_error_1[a5_0x5615('0x42')])();return process['exit'](0x1);}output[a5_0x5615('0x12')]({'title':a5_0x5615('0x8')});const _0x8c0fc6=JSON[a5_0x5615('0x27')](stripJsonComments((0x0,fs_1['readFileSync'])(workspaceRoot+'/nx.json')[a5_0x5615('0x4e')]()))['tasksRunnerOptions']['default']['options'];const _0x4c7167=getAgentName();createAgentLockfile(_0x8c0fc6,_0x4c7167);const _0x20cfc6=new distributed_agent_api_1['DistributedAgentApi'](_0x8c0fc6,_0x8be062,_0x4c7167);return executeTasks(_0x8c0fc6,_0x20cfc6)['then'](_0x184a59=>__awaiter(this,void 0x0,void 0x0,function*(){yield(0x0,metric_logger_1[a5_0x5615('0x51')])(_0x8c0fc6);return _0x184a59;}))[a5_0x5615('0x57')](_0x21b484=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x20cfc6[a5_0x5615('0x44')](a5_0x5615('0x15')+_0x21b484[a5_0x5615('0x4d')]+'\x22');throw _0x21b484;}));});}exports[a5_0x5615('0x23')]=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 stripJsonComments = require("strip-json-comments");
15
+ const distributed_agent_api_1 = require("./distributed-agent.api");
16
+ const waiter_1 = require("../../../utilities/waiter");
17
+ const environment_1 = require("../../../utilities/environment");
18
+ const print_run_group_error_1 = require("../../error/print-run-group-error");
19
+ const create_no_new_messages_timeout_1 = require("../../../utilities/create-no-new-messages-timeout");
20
+ const fs_1 = require("fs");
21
+ const metric_logger_1 = require("../../../utilities/metric-logger");
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 failIfSameTasksIn30Mins = (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
+ failIfSameTasksIn30Mins(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) {
166
+ return process.env.CIRCLE_STAGE;
167
+ }
168
+ else {
169
+ return `Agent ${Math.floor(Math.random() * 100000)}`;
170
+ }
171
+ }
172
+ function createAgentLockfile(options, agentName) {
173
+ const cacheDirectory = options.cacheDirectory || './node_modules/.cache/nx';
174
+ const lockFileDirectory = `${cacheDirectory}/lockfiles`;
175
+ const lockFilePath = `${lockFileDirectory}/${agentName}.lock`;
176
+ if (!(0, fs_1.existsSync)(lockFileDirectory)) {
177
+ (0, fs_1.mkdirSync)(lockFileDirectory, { recursive: true });
178
+ }
179
+ // Check for other agents' lockfiles and warn if exist
180
+ const lockFiles = (0, fs_1.readdirSync)(lockFileDirectory);
181
+ if (lockFiles.length) {
182
+ // Check to make sure the current agent name is not in use (only 1/100000 ^ 2 chance of this)
183
+ if (lockFiles.includes(`${agentName}.lock`)) {
184
+ output.error({
185
+ title: 'Duplicate Agent ID Detected',
186
+ bodyLines: [
187
+ 'We have detected another agent with this ID running in this workspace. This should not happen.',
188
+ '',
189
+ 'End all currently running agents, run "npx nx-cloud clean-up-agents", and try again.',
190
+ ],
191
+ });
192
+ process.exit(1);
193
+ }
194
+ output.warn({
195
+ title: 'Other Nx Cloud Agents Detected',
196
+ bodyLines: [
197
+ 'We have detected other agents running in this workspace. This can cause unexpected behavior.',
198
+ '',
199
+ 'This can also be a false positive caused by agents that did not shut down correctly.',
200
+ 'If you believe this is the case, run "npx nx-cloud clean-up-agents".',
201
+ ],
202
+ });
203
+ }
204
+ (0, fs_1.writeFileSync)(lockFilePath, '');
205
+ process.on('exit', (code) => cleanupAgentLockfile(lockFilePath, code));
206
+ process.on('SIGINT', () => cleanupAgentLockfile(lockFilePath, 0));
207
+ }
208
+ function cleanupAgentLockfile(lockFilePath, code) {
209
+ if ((0, fs_1.existsSync)(lockFilePath)) {
210
+ (0, fs_1.unlinkSync)(lockFilePath);
211
+ process.exit(code);
212
+ }
213
+ }
214
+ function startAgent() {
215
+ return __awaiter(this, void 0, void 0, function* () {
216
+ const runGroup = (0, environment_1.getRunGroup)();
217
+ if (!runGroup) {
218
+ (0, print_run_group_error_1.printRunGroupError)();
219
+ return process.exit(1);
220
+ }
221
+ output.note({
222
+ title: 'Starting an agent for running Nx tasks',
223
+ });
224
+ const options = JSON.parse(stripJsonComments((0, fs_1.readFileSync)(`${workspaceRoot}/nx.json`).toString())).tasksRunnerOptions.default.options;
225
+ const agentName = getAgentName();
226
+ createAgentLockfile(options, agentName);
227
+ const api = new distributed_agent_api_1.DistributedAgentApi(options, runGroup, agentName);
228
+ return executeTasks(options, api)
229
+ .then((res) => __awaiter(this, void 0, void 0, function* () {
230
+ yield (0, metric_logger_1.submitRunMetrics)(options);
231
+ return res;
232
+ }))
233
+ .catch((e) => __awaiter(this, void 0, void 0, function* () {
234
+ yield api.completeRunGroupWithError(`Critical Error in Agent: "${e.message}"`);
235
+ throw e;
236
+ }));
237
+ });
238
+ }
239
+ exports.startAgent = startAgent;
240
+ //# sourceMappingURL=distributed-agent.impl.js.map
@@ -1 +1,130 @@
1
- const a6_0x29c3=['target','apply','value','join','status','../../../utilities/metric-logger','then','mapRespToPerfEntry','next','createMetricRecorder','/nx-cloud/executions/start','project','../../../utilities/nx-imports','stopAgentsOnFailure','axiosException','message','throw','dteStatus','data','Workspace\x20is\x20disabled.\x20Cannot\x20perform\x20distributed\x20task\x20executions.','defineProperty','apiAxiosInstance','recordMetric','RUNNER_FAILURE_PERF_ENTRY','NX_CLOUD_DISTRIBUTED_EXECUTION_STOP_AGENTS_ON_FAILURE','parseCommand','DistributedExecutionApi','/nx-cloud/executions/status','post','getBranch','completeRunGroup','response','map','maxParallel','NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT','axiosMultipleTries','done','__esModule','completeRunGroupWithError','error','true','__awaiter','parallel','exit','start'];(function(_0x3b8619,_0x29c3c7){const _0x4b8b2c=function(_0x279801){while(--_0x279801){_0x3b8619['push'](_0x3b8619['shift']());}};_0x4b8b2c(++_0x29c3c7);}(a6_0x29c3,0x15e));const a6_0x4b8b=function(_0x3b8619,_0x29c3c7){_0x3b8619=_0x3b8619-0x0;let _0x4b8b2c=a6_0x29c3[_0x3b8619];return _0x4b8b2c;};'use strict';var __awaiter=this&&this[a6_0x4b8b('0x6')]||function(_0x407b6d,_0x180953,_0x201a15,_0x53feb6){function _0xdbdea0(_0x37163e){return _0x37163e instanceof _0x201a15?_0x37163e:new _0x201a15(function(_0x1c830c){_0x1c830c(_0x37163e);});}return new(_0x201a15||(_0x201a15=Promise))(function(_0x449614,_0x8ece6){function _0x431e6d(_0x504b84){try{_0x287417(_0x53feb6[a6_0x4b8b('0x12')](_0x504b84));}catch(_0x497388){_0x8ece6(_0x497388);}}function _0x228921(_0x3245d3){try{_0x287417(_0x53feb6[a6_0x4b8b('0x1a')](_0x3245d3));}catch(_0x5db920){_0x8ece6(_0x5db920);}}function _0x287417(_0x1f815c){_0x1f815c[a6_0x4b8b('0x1')]?_0x449614(_0x1f815c[a6_0x4b8b('0xc')]):_0xdbdea0(_0x1f815c[a6_0x4b8b('0xc')])[a6_0x4b8b('0x10')](_0x431e6d,_0x228921);}_0x287417((_0x53feb6=_0x53feb6[a6_0x4b8b('0xb')](_0x407b6d,_0x180953||[]))[a6_0x4b8b('0x12')]());});};Object[a6_0x4b8b('0x1e')](exports,a6_0x4b8b('0x2'),{'value':!![]});exports['createStartRequest']=exports[a6_0x4b8b('0x24')]=void 0x0;const axios_1=require('../../../utilities/axios');const environment_1=require('../../../utilities/environment');const metric_logger_1=require(a6_0x4b8b('0xf'));const {output,unparse}=require(a6_0x4b8b('0x16'));class DistributedExecutionApi{constructor(_0x20fa9f){this['apiAxiosInstance']=(0x0,axios_1['createApiAxiosInstance'])(_0x20fa9f);}[a6_0x4b8b('0x9')](_0x46a09b){var _0x41e071;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x5189b5=(0x0,metric_logger_1[a6_0x4b8b('0x13')])('dteStart');let _0x3cad43;try{_0x3cad43=yield(0x0,axios_1[a6_0x4b8b('0x0')])(()=>this[a6_0x4b8b('0x1f')]['post'](a6_0x4b8b('0x14'),_0x46a09b));_0x5189b5[a6_0x4b8b('0x20')]((0x0,metric_logger_1[a6_0x4b8b('0x11')])(_0x3cad43));}catch(_0x1adb92){_0x5189b5[a6_0x4b8b('0x20')](((_0x41e071=_0x1adb92===null||_0x1adb92===void 0x0?void 0x0:_0x1adb92[a6_0x4b8b('0x18')])===null||_0x41e071===void 0x0?void 0x0:_0x41e071[a6_0x4b8b('0x29')])?(0x0,metric_logger_1[a6_0x4b8b('0x11')])(_0x1adb92['axiosException'][a6_0x4b8b('0x29')]):metric_logger_1[a6_0x4b8b('0x21')]);throw _0x1adb92;}if(!_0x3cad43[a6_0x4b8b('0x1c')]['enabled']){throw new Error(a6_0x4b8b('0x1d'));}if(_0x3cad43[a6_0x4b8b('0x1c')][a6_0x4b8b('0x4')]){throw new Error(_0x3cad43['data']['error']);}return _0x3cad43[a6_0x4b8b('0x1c')]['id'];});}[a6_0x4b8b('0xe')](_0x53c0ec){var _0x3bc9af;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x41edea=(0x0,metric_logger_1['createMetricRecorder'])(a6_0x4b8b('0x1b'));try{const _0xd0d28f=yield(0x0,axios_1[a6_0x4b8b('0x0')])(()=>this[a6_0x4b8b('0x1f')][a6_0x4b8b('0x26')](a6_0x4b8b('0x25'),{'id':_0x53c0ec}));_0x41edea[a6_0x4b8b('0x20')]((0x0,metric_logger_1['mapRespToPerfEntry'])(_0xd0d28f));return _0xd0d28f[a6_0x4b8b('0x1c')];}catch(_0x38cfa0){_0x41edea[a6_0x4b8b('0x20')](((_0x3bc9af=_0x38cfa0===null||_0x38cfa0===void 0x0?void 0x0:_0x38cfa0[a6_0x4b8b('0x18')])===null||_0x3bc9af===void 0x0?void 0x0:_0x3bc9af['response'])?(0x0,metric_logger_1[a6_0x4b8b('0x11')])(_0x38cfa0[a6_0x4b8b('0x18')]['response']):metric_logger_1[a6_0x4b8b('0x21')]);output[a6_0x4b8b('0x4')]({'title':_0x38cfa0[a6_0x4b8b('0x19')]});process[a6_0x4b8b('0x8')](0x1);}});}[a6_0x4b8b('0x3')](_0x3f8831,_0x17c509){var _0x14daba;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x6f0561=(0x0,metric_logger_1['createMetricRecorder'])(a6_0x4b8b('0x28'));try{const _0x2862b9=yield(0x0,axios_1[a6_0x4b8b('0x0')])(()=>this[a6_0x4b8b('0x1f')][a6_0x4b8b('0x26')]('/nx-cloud/executions/complete-run-group',{'runGroup':_0x3f8831,'criticalErrorMessage':_0x17c509}),0x3);_0x6f0561[a6_0x4b8b('0x20')]((0x0,metric_logger_1[a6_0x4b8b('0x11')])(_0x2862b9));}catch(_0xde1497){_0x6f0561[a6_0x4b8b('0x20')](((_0x14daba=_0xde1497===null||_0xde1497===void 0x0?void 0x0:_0xde1497[a6_0x4b8b('0x18')])===null||_0x14daba===void 0x0?void 0x0:_0x14daba[a6_0x4b8b('0x29')])?(0x0,metric_logger_1[a6_0x4b8b('0x11')])(_0xde1497[a6_0x4b8b('0x18')][a6_0x4b8b('0x29')]):metric_logger_1['RUNNER_FAILURE_PERF_ENTRY']);}});}}exports[a6_0x4b8b('0x24')]=DistributedExecutionApi;function createStartRequest(_0x5b5f71,_0x3274de,_0x3956ca){const _0x531b87=_0x3274de['map'](_0x1609b7=>{return _0x1609b7[a6_0x4b8b('0x2a')](_0x3734e8=>{return{'taskId':_0x3734e8['id'],'hash':_0x3734e8['hash'],'projectName':_0x3734e8[a6_0x4b8b('0xa')][a6_0x4b8b('0x15')],'target':_0x3734e8[a6_0x4b8b('0xa')][a6_0x4b8b('0xa')],'configuration':_0x3734e8['target']['configuration']||null,'params':unparse(_0x3734e8['overrides'])[a6_0x4b8b('0xd')]('\x20')};});});const _0x270b9a={'command':(0x0,environment_1[a6_0x4b8b('0x23')])(),'branch':(0x0,environment_1[a6_0x4b8b('0x27')])(),'runGroup':_0x5b5f71,'tasks':_0x531b87,'maxParallel':calculateMaxParallel(_0x3956ca)};if(environment_1[a6_0x4b8b('0x2c')]){_0x270b9a['agentCount']=environment_1[a6_0x4b8b('0x2c')];}if(!environment_1[a6_0x4b8b('0x22')]){_0x270b9a[a6_0x4b8b('0x17')]=![];}return _0x270b9a;}exports['createStartRequest']=createStartRequest;function calculateMaxParallel(_0x496534){if(_0x496534[a6_0x4b8b('0x7')]==='false'||_0x496534[a6_0x4b8b('0x7')]===![]){return 0x1;}else if(_0x496534[a6_0x4b8b('0x7')]===a6_0x4b8b('0x5')||_0x496534[a6_0x4b8b('0x7')]===!![]){return Number(_0x496534[a6_0x4b8b('0x2b')]||0x3);}else if(_0x496534['parallel']===undefined){return _0x496534[a6_0x4b8b('0x2b')]?Number(_0x496534[a6_0x4b8b('0x2b')]):0x3;}else{return Number(_0x496534[a6_0x4b8b('0x7')])||0x3;}}
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 { output, unparse } = require('../../../utilities/nx-imports');
17
+ class DistributedExecutionApi {
18
+ constructor(options) {
19
+ this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options);
20
+ }
21
+ start(params) {
22
+ var _a;
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const recorder = (0, metric_logger_1.createMetricRecorder)('dteStart');
25
+ let resp;
26
+ try {
27
+ resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/start', params));
28
+ recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
29
+ }
30
+ catch (e) {
31
+ recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
32
+ ? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
33
+ : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
34
+ throw e;
35
+ }
36
+ if (!resp.data.enabled) {
37
+ throw new Error(`Workspace is disabled. Cannot perform distributed task executions.`);
38
+ }
39
+ if (resp.data.error) {
40
+ throw new Error(resp.data.error);
41
+ }
42
+ return resp.data.id;
43
+ });
44
+ }
45
+ status(id) {
46
+ var _a;
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const recorder = (0, metric_logger_1.createMetricRecorder)('dteStatus');
49
+ try {
50
+ const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/status', {
51
+ id,
52
+ }));
53
+ recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
54
+ return resp.data;
55
+ }
56
+ catch (e) {
57
+ recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
58
+ ? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
59
+ : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
60
+ output.error({
61
+ title: e.message,
62
+ });
63
+ process.exit(1);
64
+ }
65
+ });
66
+ }
67
+ completeRunGroupWithError(runGroup, error) {
68
+ var _a;
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ const recorder = (0, metric_logger_1.createMetricRecorder)('completeRunGroup');
71
+ try {
72
+ const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/complete-run-group', {
73
+ runGroup: runGroup,
74
+ criticalErrorMessage: error,
75
+ }), 3);
76
+ recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
77
+ }
78
+ catch (e) {
79
+ recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
80
+ ? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
81
+ : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
82
+ }
83
+ });
84
+ }
85
+ }
86
+ exports.DistributedExecutionApi = DistributedExecutionApi;
87
+ function createStartRequest(runGroup, task, options) {
88
+ const tasksToExecute = task.map((arr) => {
89
+ return arr.map((t) => {
90
+ return {
91
+ taskId: t.id,
92
+ hash: t.hash,
93
+ projectName: t.target.project,
94
+ target: t.target.target,
95
+ configuration: t.target.configuration || null,
96
+ params: unparse(t.overrides).join(' '),
97
+ };
98
+ });
99
+ });
100
+ const request = {
101
+ command: (0, environment_1.parseCommand)(),
102
+ branch: (0, environment_1.getBranch)(),
103
+ runGroup,
104
+ tasks: tasksToExecute,
105
+ maxParallel: calculateMaxParallel(options),
106
+ };
107
+ if (environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT) {
108
+ request.agentCount = environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT;
109
+ }
110
+ if (!environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_STOP_AGENTS_ON_FAILURE) {
111
+ request.stopAgentsOnFailure = false;
112
+ }
113
+ return request;
114
+ }
115
+ exports.createStartRequest = createStartRequest;
116
+ function calculateMaxParallel(options) {
117
+ if (options.parallel === 'false' || options.parallel === false) {
118
+ return 1;
119
+ }
120
+ else if (options.parallel === 'true' || options.parallel === true) {
121
+ return Number(options.maxParallel || 3);
122
+ }
123
+ else if (options.parallel === undefined) {
124
+ return options.maxParallel ? Number(options.maxParallel) : 3;
125
+ }
126
+ else {
127
+ return Number(options.parallel) || 3;
128
+ }
129
+ }
130
+ //# sourceMappingURL=distributed-execution.api.js.map