@nrwl/nx-cloud 14.1.3-beta.2 → 14.2.0

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,243 +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.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 && 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
+ 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,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
1
+ const a6_0x3857=['target','message','/nx-cloud/executions/complete-run-group','__awaiter','/nx-cloud/executions/start','axiosMultipleTries','../../../utilities/environment','DistributedExecutionApi','recordMetric','NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT','status','../../../utilities/axios','dteStart','false','response','defineProperty','createStartRequest','next','/nx-cloud/executions/status','error','hash','../../../utilities/nx-imports','createApiAxiosInstance','apply','__esModule','Workspace\x20is\x20disabled.\x20Cannot\x20perform\x20distributed\x20task\x20executions.','data','parallel','createMetricRecorder','start','getBranch','agentCount','dteStatus','done','then','value','post','enabled','project','axiosException','completeRunGroup','configuration','apiAxiosInstance','../../../utilities/serializer-overrides','../../../utilities/metric-logger','mapRespToPerfEntry','maxParallel','parseCommand'];(function(_0x599e1e,_0x3857d4){const _0x2214d7=function(_0x1ae588){while(--_0x1ae588){_0x599e1e['push'](_0x599e1e['shift']());}};_0x2214d7(++_0x3857d4);}(a6_0x3857,0x1dc));const a6_0x2214=function(_0x599e1e,_0x3857d4){_0x599e1e=_0x599e1e-0x0;let _0x2214d7=a6_0x3857[_0x599e1e];return _0x2214d7;};'use strict';var __awaiter=this&&this[a6_0x2214('0x7')]||function(_0x1c79d3,_0x2e4fe9,_0x6decdd,_0x2d69ae){function _0x21aaa2(_0x596e31){return _0x596e31 instanceof _0x6decdd?_0x596e31:new _0x6decdd(function(_0x2d4904){_0x2d4904(_0x596e31);});}return new(_0x6decdd||(_0x6decdd=Promise))(function(_0x56c2ca,_0x1538a6){function _0x5b23a4(_0x3efc79){try{_0x3058d9(_0x2d69ae[a6_0x2214('0x15')](_0x3efc79));}catch(_0x3b23fa){_0x1538a6(_0x3b23fa);}}function _0x54c63d(_0x3b19d5){try{_0x3058d9(_0x2d69ae['throw'](_0x3b19d5));}catch(_0x274122){_0x1538a6(_0x274122);}}function _0x3058d9(_0x25faf2){_0x25faf2[a6_0x2214('0x25')]?_0x56c2ca(_0x25faf2[a6_0x2214('0x27')]):_0x21aaa2(_0x25faf2[a6_0x2214('0x27')])[a6_0x2214('0x26')](_0x5b23a4,_0x54c63d);}_0x3058d9((_0x2d69ae=_0x2d69ae[a6_0x2214('0x1b')](_0x1c79d3,_0x2e4fe9||[]))[a6_0x2214('0x15')]());});};Object[a6_0x2214('0x13')](exports,a6_0x2214('0x1c'),{'value':!![]});exports['createStartRequest']=exports[a6_0x2214('0xb')]=void 0x0;const axios_1=require(a6_0x2214('0xf'));const environment_1=require(a6_0x2214('0xa'));const metric_logger_1=require(a6_0x2214('0x0'));const serializer_overrides_1=require(a6_0x2214('0x2f'));const {output,unparse}=require(a6_0x2214('0x19'));class DistributedExecutionApi{constructor(_0x397892){this[a6_0x2214('0x2e')]=(0x0,axios_1[a6_0x2214('0x1a')])(_0x397892);}[a6_0x2214('0x21')](_0x1155d6){var _0x4928c4;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x380316=(0x0,metric_logger_1['createMetricRecorder'])(a6_0x2214('0x10'));let _0x3d15f9;try{_0x3d15f9=yield(0x0,axios_1[a6_0x2214('0x9')])(()=>this[a6_0x2214('0x2e')][a6_0x2214('0x28')](a6_0x2214('0x8'),_0x1155d6));_0x380316[a6_0x2214('0xc')]((0x0,metric_logger_1[a6_0x2214('0x1')])(_0x3d15f9));}catch(_0x255a4a){_0x380316['recordMetric'](((_0x4928c4=_0x255a4a===null||_0x255a4a===void 0x0?void 0x0:_0x255a4a[a6_0x2214('0x2b')])===null||_0x4928c4===void 0x0?void 0x0:_0x4928c4[a6_0x2214('0x12')])?(0x0,metric_logger_1['mapRespToPerfEntry'])(_0x255a4a[a6_0x2214('0x2b')][a6_0x2214('0x12')]):metric_logger_1['RUNNER_FAILURE_PERF_ENTRY']);throw _0x255a4a;}if(!_0x3d15f9[a6_0x2214('0x1e')][a6_0x2214('0x29')]){throw new Error(a6_0x2214('0x1d'));}if(_0x3d15f9[a6_0x2214('0x1e')][a6_0x2214('0x17')]){throw new Error(_0x3d15f9[a6_0x2214('0x1e')][a6_0x2214('0x17')]);}return _0x3d15f9[a6_0x2214('0x1e')]['id'];});}[a6_0x2214('0xe')](_0x6042af){var _0x2bed14;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x3565df=(0x0,metric_logger_1[a6_0x2214('0x20')])(a6_0x2214('0x24'));try{const _0x4258ef=yield(0x0,axios_1[a6_0x2214('0x9')])(()=>this[a6_0x2214('0x2e')][a6_0x2214('0x28')](a6_0x2214('0x16'),{'id':_0x6042af}));_0x3565df[a6_0x2214('0xc')]((0x0,metric_logger_1[a6_0x2214('0x1')])(_0x4258ef));return _0x4258ef[a6_0x2214('0x1e')];}catch(_0x43a24a){_0x3565df['recordMetric'](((_0x2bed14=_0x43a24a===null||_0x43a24a===void 0x0?void 0x0:_0x43a24a[a6_0x2214('0x2b')])===null||_0x2bed14===void 0x0?void 0x0:_0x2bed14[a6_0x2214('0x12')])?(0x0,metric_logger_1[a6_0x2214('0x1')])(_0x43a24a[a6_0x2214('0x2b')][a6_0x2214('0x12')]):metric_logger_1['RUNNER_FAILURE_PERF_ENTRY']);output[a6_0x2214('0x17')]({'title':_0x43a24a[a6_0x2214('0x5')]});process['exit'](0x1);}});}['completeRunGroupWithError'](_0x49ee80,_0x166a3d){var _0x17e17d;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x3646a7=(0x0,metric_logger_1[a6_0x2214('0x20')])(a6_0x2214('0x2c'));try{const _0x79117b=yield(0x0,axios_1[a6_0x2214('0x9')])(()=>this[a6_0x2214('0x2e')]['post'](a6_0x2214('0x6'),{'runGroup':_0x49ee80,'criticalErrorMessage':_0x166a3d}),0x3);_0x3646a7[a6_0x2214('0xc')]((0x0,metric_logger_1['mapRespToPerfEntry'])(_0x79117b));}catch(_0x303cf3){_0x3646a7[a6_0x2214('0xc')](((_0x17e17d=_0x303cf3===null||_0x303cf3===void 0x0?void 0x0:_0x303cf3[a6_0x2214('0x2b')])===null||_0x17e17d===void 0x0?void 0x0:_0x17e17d[a6_0x2214('0x12')])?(0x0,metric_logger_1[a6_0x2214('0x1')])(_0x303cf3[a6_0x2214('0x2b')]['response']):metric_logger_1['RUNNER_FAILURE_PERF_ENTRY']);}});}}exports[a6_0x2214('0xb')]=DistributedExecutionApi;function createStartRequest(_0x21f75d,_0x40dfce,_0x33559f){const _0x50e906=_0x40dfce['map'](_0x3441bb=>{return _0x3441bb['map'](_0x2e4602=>{return{'taskId':_0x2e4602['id'],'hash':_0x2e4602[a6_0x2214('0x18')],'projectName':_0x2e4602[a6_0x2214('0x4')][a6_0x2214('0x2a')],'target':_0x2e4602[a6_0x2214('0x4')][a6_0x2214('0x4')],'configuration':_0x2e4602[a6_0x2214('0x4')][a6_0x2214('0x2d')]||null,'params':(0x0,serializer_overrides_1['serializeOverrides'])(_0x2e4602)};});});const _0x13df5={'command':(0x0,environment_1[a6_0x2214('0x3')])(),'branch':(0x0,environment_1[a6_0x2214('0x22')])(),'runGroup':_0x21f75d,'tasks':_0x50e906,'maxParallel':calculateMaxParallel(_0x33559f)};if(environment_1[a6_0x2214('0xd')]){_0x13df5[a6_0x2214('0x23')]=environment_1[a6_0x2214('0xd')];}if(!environment_1['NX_CLOUD_DISTRIBUTED_EXECUTION_STOP_AGENTS_ON_FAILURE']){_0x13df5['stopAgentsOnFailure']=![];}return _0x13df5;}exports[a6_0x2214('0x14')]=createStartRequest;function calculateMaxParallel(_0x69609a){if(_0x69609a[a6_0x2214('0x1f')]===a6_0x2214('0x11')||_0x69609a[a6_0x2214('0x1f')]===![]){return 0x1;}else if(_0x69609a[a6_0x2214('0x1f')]==='true'||_0x69609a[a6_0x2214('0x1f')]===!![]){return Number(_0x69609a[a6_0x2214('0x2')]||0x3);}else if(_0x69609a[a6_0x2214('0x1f')]===undefined){return _0x69609a[a6_0x2214('0x2')]?Number(_0x69609a['maxParallel']):0x3;}else{return Number(_0x69609a['parallel'])||0x3;}}
@@ -1,206 +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.nxCloudDistributedTasksRunner = void 0;
13
- const stripJsonComments = require("strip-json-comments");
14
- const fs_1 = require("fs");
15
- const distributed_execution_api_1 = require("./distributed-execution.api");
16
- const file_storage_1 = require("../../file-storage/file-storage");
17
- const e2e_encryption_1 = require("../../file-storage/e2e-encryption");
18
- const waiter_1 = require("../../../utilities/waiter");
19
- const environment_1 = require("../../../utilities/environment");
20
- const print_run_group_error_1 = require("../../error/print-run-group-error");
21
- const create_no_new_messages_timeout_1 = require("../../../utilities/create-no-new-messages-timeout");
22
- const metric_logger_1 = require("../../../utilities/metric-logger");
23
- const error_reporter_api_1 = require("../../api/error-reporter.api");
24
- const serializer_overrides_1 = require("../../../utilities/serializer-overrides");
25
- const task_graph_creator_1 = require("./task-graph-creator");
26
- const split_task_graph_into_stages_1 = require("./split-task-graph-into-stages");
27
- const { output, workspaceRoot, getOutputs, Cache, } = require('../../../utilities/nx-imports');
28
- class NoopLifeCycle {
29
- scheduleTask(task) { }
30
- startTask(task) { }
31
- endTask(task, code) { }
32
- }
33
- function runDistributedExecution(api, options, context, fileStorage, cache, runGroup, taskGraph) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- const id = yield api.start((0, distributed_execution_api_1.createStartRequest)(runGroup, (0, split_task_graph_into_stages_1.splitTasksIntoStages)(taskGraph), options));
36
- return yield processTasks(api, fileStorage, cache, options, id, Object.values(taskGraph.tasks), context);
37
- });
38
- }
39
- function processTasks(api, fileStorage, cache, options, executionId, tasks, context) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- const processedTasks = {};
42
- const failIfNumberOfCompletedTasksDoesNotChangeIn30Mins = (0, create_no_new_messages_timeout_1.createNoNewMessagesTimeout)();
43
- const waiter = new waiter_1.Waiter();
44
- while (true) {
45
- if (environment_1.VERBOSE_LOGGING) {
46
- output.note({
47
- title: 'Waiting...',
48
- });
49
- }
50
- yield waiter.wait();
51
- const r = yield api.status(executionId);
52
- if (environment_1.VERBOSE_LOGGING) {
53
- output.note({
54
- title: `Status update`,
55
- bodyLines: [
56
- `executionId: ${executionId}`,
57
- `executionStatus: ${r.executionStatus}`,
58
- `number of completed tasks: ${r.completedTasks.length}`,
59
- `error: ${r.criticalErrorMessage}`,
60
- ],
61
- });
62
- }
63
- if (r.criticalErrorMessage) {
64
- output.error({
65
- title: 'Distributed Execution Terminated',
66
- bodyLines: ['Error:', r.criticalErrorMessage],
67
- });
68
- process.exit(1);
69
- }
70
- failIfNumberOfCompletedTasksDoesNotChangeIn30Mins(r.completedTasks.length);
71
- for (const t of r.completedTasks) {
72
- if (processedTasks[t.taskId])
73
- continue;
74
- yield processTask(fileStorage, cache, context, options, tasks, t);
75
- waiter.reset();
76
- processedTasks[t.taskId] = true;
77
- }
78
- if (r.executionStatus === 'COMPLETED') {
79
- return { commandStatus: r.commandStatus, runUrl: r.runUrl };
80
- }
81
- }
82
- });
83
- }
84
- function processTask(fileStorage, cache, context, options, tasks, completedTask) {
85
- return __awaiter(this, void 0, void 0, function* () {
86
- if (environment_1.VERBOSE_LOGGING) {
87
- output.note({
88
- title: `Processing task ${completedTask.taskId}`,
89
- });
90
- }
91
- const matchingTask = tasks.find((tt) => completedTask.taskId === tt.id);
92
- if (!matchingTask) {
93
- throw new Error(`Found unknown task: ${completedTask.taskId}`);
94
- }
95
- if (environment_1.VERBOSE_LOGGING) {
96
- output.note({
97
- title: `Retrieving artifacts from ${completedTask.url}`,
98
- });
99
- }
100
- yield fileStorage.retrieve(completedTask.hash, completedTask.url, options.cacheDirectory || './node_modules/.cache/nx');
101
- const cachedResult = yield cache.get(Object.assign(Object.assign({}, matchingTask), { hash: completedTask.hash }));
102
- const outputs = getOutputs(context.projectGraph.nodes, matchingTask);
103
- if (environment_1.VERBOSE_LOGGING) {
104
- output.note({
105
- title: `Extracting artifacts`,
106
- bodyLines: outputs,
107
- });
108
- }
109
- yield cache.copyFilesFromCache(completedTask.hash, cachedResult, outputs);
110
- output.logCommand(getCommand(matchingTask));
111
- process.stdout.write(cachedResult.terminalOutput);
112
- output.addVerticalSeparator();
113
- });
114
- }
115
- function getCommand(task) {
116
- const config = task.target.configuration
117
- ? `:${task.target.configuration}`
118
- : '';
119
- return [
120
- 'nx',
121
- 'run',
122
- `${task.target.project}:${task.target.target}${config}`,
123
- (0, serializer_overrides_1.serializeOverrides)(task),
124
- ].join(' ');
125
- }
126
- const nxCloudDistributedTasksRunner = (tasks, options, context) => __awaiter(void 0, void 0, void 0, function* () {
127
- if (environment_1.VERBOSE_LOGGING) {
128
- output.note({
129
- title: 'Starting distributed command execution',
130
- });
131
- }
132
- options.lifeCycle = new NoopLifeCycle();
133
- const runGroup = (0, environment_1.getRunGroup)();
134
- if (!runGroup) {
135
- (0, print_run_group_error_1.printRunGroupError)();
136
- return process.exit(1);
137
- }
138
- const encryption = new e2e_encryption_1.E2EEncryption(environment_1.ENCRYPTION_KEY || options.encryptionKey);
139
- const errorReporter = new error_reporter_api_1.ErrorReporterApi(options);
140
- const fileStorage = new file_storage_1.FileStorage(encryption, errorReporter, true);
141
- const cache = new Cache(options);
142
- const api = new distributed_execution_api_1.DistributedExecutionApi(options);
143
- try {
144
- const taskGraph = getTaskGraph(context, tasks, options);
145
- const r = yield runDistributedExecution(api, options, context, fileStorage, cache, runGroup, taskGraph);
146
- if (r.commandStatus === 0) {
147
- output.success({
148
- title: 'Successfully completed running the command.',
149
- bodyLines: [`See run details at ${r.runUrl}`],
150
- });
151
- }
152
- else {
153
- output.error({
154
- title: 'Command execution failed.',
155
- bodyLines: [`See run details at ${r.runUrl}`],
156
- });
157
- }
158
- yield (0, metric_logger_1.submitRunMetrics)(options);
159
- process.exit(r.commandStatus);
160
- }
161
- catch (e) {
162
- output.error({
163
- title: 'Unable to complete a run.',
164
- bodyLines: [e.message],
165
- });
166
- if (e.axiosException) {
167
- console.log(e.axiosException);
168
- }
169
- else {
170
- console.log(e);
171
- }
172
- try {
173
- yield api.completeRunGroupWithError(runGroup, `Main job terminated with an error: "${e.message}"`);
174
- }
175
- finally {
176
- process.exit(1);
177
- }
178
- }
179
- });
180
- exports.nxCloudDistributedTasksRunner = nxCloudDistributedTasksRunner;
181
- function getTaskGraph(context, tasks, options) {
182
- if (context.taskGraph) {
183
- return context.taskGraph;
184
- }
185
- else {
186
- const nxjson = JSON.parse(stripJsonComments((0, fs_1.readFileSync)(`${workspaceRoot}/nx.json`).toString()));
187
- return new task_graph_creator_1.TaskGraphCreator(context.projectGraph, getDefaultDependencyConfigs(nxjson, options)).createTaskGraph(tasks);
188
- }
189
- }
190
- function getDefaultDependencyConfigs(nxJson, runnerOptions) {
191
- var _a, _b;
192
- const defaults = (_a = nxJson.targetDependencies) !== null && _a !== void 0 ? _a : {};
193
- const strictlyOrderedTargets = runnerOptions
194
- ? (_b = runnerOptions.strictlyOrderedTargets) !== null && _b !== void 0 ? _b : ['build']
195
- : [];
196
- // Strictly Ordered Targets depend on their dependencies
197
- for (const target of strictlyOrderedTargets) {
198
- defaults[target] = defaults[target] || [];
199
- defaults[target].push({
200
- target,
201
- projects: 'dependencies',
202
- });
203
- }
204
- return defaults;
205
- }
206
- //# sourceMappingURL=distributed-execution.runner.js.map
1
+ const a7_0x37ea=['Processing\x20task\x20','parse','start','write','note','__esModule','stdout','executionId:\x20','Command\x20execution\x20failed.','commandStatus','ErrorReporterApi','./task-graph-creator','project','../../file-storage/file-storage','Unable\x20to\x20complete\x20a\x20run.','log','encryptionKey','DistributedExecutionApi','strip-json-comments','ENCRYPTION_KEY','VERBOSE_LOGGING','executionStatus:\x20','completeRunGroupWithError','logCommand','values','push','cacheDirectory','/nx.json','TaskGraphCreator','copyFilesFromCache','nxCloudDistributedTasksRunner','completedTasks','executionStatus','taskGraph','error','criticalErrorMessage','reset','Waiter','addVerticalSeparator','Starting\x20distributed\x20command\x20execution','submitRunMetrics','../../../utilities/serializer-overrides','retrieve','value','get','url','number\x20of\x20completed\x20tasks:\x20','nodes','Waiting...','Status\x20update','Found\x20unknown\x20task:\x20','../../error/print-run-group-error','Retrieving\x20artifacts\x20from\x20','message','assign','createNoNewMessagesTimeout','./node_modules/.cache/nx','hash','length','projectGraph','createTaskGraph','axiosException','terminalOutput','Error:','Distributed\x20Execution\x20Terminated','runUrl','__awaiter','splitTasksIntoStages','Main\x20job\x20terminated\x20with\x20an\x20error:\x20\x22','../../../utilities/nx-imports','next','serializeOverrides','target','configuration','createStartRequest','scheduleTask','targetDependencies','startTask','exit','dependencies','../../../utilities/create-no-new-messages-timeout','../../../utilities/waiter','Successfully\x20completed\x20running\x20the\x20command.','taskId'];(function(_0x52e5f3,_0x37ea81){const _0x21105f=function(_0x5f1313){while(--_0x5f1313){_0x52e5f3['push'](_0x52e5f3['shift']());}};_0x21105f(++_0x37ea81);}(a7_0x37ea,0x1c0));const a7_0x2110=function(_0x52e5f3,_0x37ea81){_0x52e5f3=_0x52e5f3-0x0;let _0x21105f=a7_0x37ea[_0x52e5f3];return _0x21105f;};'use strict';var __awaiter=this&&this[a7_0x2110('0x26')]||function(_0x1a56e7,_0x2ddfa9,_0x47676e,_0x59c121){function _0x57a7dc(_0x1c6467){return _0x1c6467 instanceof _0x47676e?_0x1c6467:new _0x47676e(function(_0x4d08e9){_0x4d08e9(_0x1c6467);});}return new(_0x47676e||(_0x47676e=Promise))(function(_0x248065,_0x2a5ebd){function _0xac444f(_0x557861){try{_0x4fb081(_0x59c121['next'](_0x557861));}catch(_0x4baa0b){_0x2a5ebd(_0x4baa0b);}}function _0x6b403c(_0x148063){try{_0x4fb081(_0x59c121['throw'](_0x148063));}catch(_0x569192){_0x2a5ebd(_0x569192);}}function _0x4fb081(_0x2aa6ae){_0x2aa6ae['done']?_0x248065(_0x2aa6ae[a7_0x2110('0xf')]):_0x57a7dc(_0x2aa6ae['value'])['then'](_0xac444f,_0x6b403c);}_0x4fb081((_0x59c121=_0x59c121['apply'](_0x1a56e7,_0x2ddfa9||[]))[a7_0x2110('0x2a')]());});};Object['defineProperty'](exports,a7_0x2110('0x3d'),{'value':!![]});exports[a7_0x2110('0x2')]=void 0x0;const stripJsonComments=require(a7_0x2110('0x4a'));const fs_1=require('fs');const distributed_execution_api_1=require('./distributed-execution.api');const file_storage_1=require(a7_0x2110('0x45'));const e2e_encryption_1=require('../../file-storage/e2e-encryption');const waiter_1=require(a7_0x2110('0x35'));const environment_1=require('../../../utilities/environment');const print_run_group_error_1=require(a7_0x2110('0x17'));const create_no_new_messages_timeout_1=require(a7_0x2110('0x34'));const metric_logger_1=require('../../../utilities/metric-logger');const error_reporter_api_1=require('../../api/error-reporter.api');const serializer_overrides_1=require(a7_0x2110('0xd'));const task_graph_creator_1=require(a7_0x2110('0x43'));const split_task_graph_into_stages_1=require('./split-task-graph-into-stages');const {output,workspaceRoot,getOutputs,Cache}=require(a7_0x2110('0x29'));class NoopLifeCycle{[a7_0x2110('0x2f')](_0x1b277b){}[a7_0x2110('0x31')](_0x26ca54){}['endTask'](_0x33e2b2,_0x303a28){}}function runDistributedExecution(_0x4d3098,_0x297729,_0x54791c,_0x158def,_0x2c6984,_0x2af478,_0x548078){return __awaiter(this,void 0x0,void 0x0,function*(){const _0xfbbef3=yield _0x4d3098[a7_0x2110('0x3a')]((0x0,distributed_execution_api_1[a7_0x2110('0x2e')])(_0x2af478,(0x0,split_task_graph_into_stages_1[a7_0x2110('0x27')])(_0x548078),_0x297729));return yield processTasks(_0x4d3098,_0x158def,_0x2c6984,_0x297729,_0xfbbef3,Object[a7_0x2110('0x50')](_0x548078['tasks']),_0x54791c);});}function processTasks(_0x215c04,_0x36e60e,_0x328fd1,_0x40885a,_0x2bc7e2,_0x402edd,_0x229fb6){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x4e6094={};const _0x494780=(0x0,create_no_new_messages_timeout_1[a7_0x2110('0x1b')])();const _0xbe69cb=new waiter_1[(a7_0x2110('0x9'))]();while(!![]){if(environment_1[a7_0x2110('0x4c')]){output['note']({'title':a7_0x2110('0x14')});}yield _0xbe69cb['wait']();const _0x22655e=yield _0x215c04['status'](_0x2bc7e2);if(environment_1[a7_0x2110('0x4c')]){output['note']({'title':a7_0x2110('0x15'),'bodyLines':[a7_0x2110('0x3f')+_0x2bc7e2,a7_0x2110('0x4d')+_0x22655e[a7_0x2110('0x4')],a7_0x2110('0x12')+_0x22655e[a7_0x2110('0x3')][a7_0x2110('0x1e')],'error:\x20'+_0x22655e[a7_0x2110('0x7')]]});}if(_0x22655e[a7_0x2110('0x7')]){output[a7_0x2110('0x6')]({'title':a7_0x2110('0x24'),'bodyLines':[a7_0x2110('0x23'),_0x22655e['criticalErrorMessage']]});process[a7_0x2110('0x32')](0x1);}_0x494780(_0x22655e[a7_0x2110('0x3')][a7_0x2110('0x1e')]);for(const _0x3f90fc of _0x22655e[a7_0x2110('0x3')]){if(_0x4e6094[_0x3f90fc[a7_0x2110('0x37')]])continue;yield processTask(_0x36e60e,_0x328fd1,_0x229fb6,_0x40885a,_0x402edd,_0x3f90fc);_0xbe69cb[a7_0x2110('0x8')]();_0x4e6094[_0x3f90fc[a7_0x2110('0x37')]]=!![];}if(_0x22655e[a7_0x2110('0x4')]==='COMPLETED'){return{'commandStatus':_0x22655e[a7_0x2110('0x41')],'runUrl':_0x22655e[a7_0x2110('0x25')]};}}});}function processTask(_0x1aa5df,_0x4803f5,_0x3a6aab,_0x4f823f,_0x2f9376,_0x12407b){return __awaiter(this,void 0x0,void 0x0,function*(){if(environment_1[a7_0x2110('0x4c')]){output[a7_0x2110('0x3c')]({'title':a7_0x2110('0x38')+_0x12407b[a7_0x2110('0x37')]});}const _0x417e9a=_0x2f9376['find'](_0x19394b=>_0x12407b[a7_0x2110('0x37')]===_0x19394b['id']);if(!_0x417e9a){throw new Error(a7_0x2110('0x16')+_0x12407b[a7_0x2110('0x37')]);}if(environment_1[a7_0x2110('0x4c')]){output[a7_0x2110('0x3c')]({'title':a7_0x2110('0x18')+_0x12407b[a7_0x2110('0x11')]});}yield _0x1aa5df[a7_0x2110('0xe')](_0x12407b['hash'],_0x12407b[a7_0x2110('0x11')],_0x4f823f[a7_0x2110('0x52')]||a7_0x2110('0x1c'));const _0x444ddf=yield _0x4803f5[a7_0x2110('0x10')](Object[a7_0x2110('0x1a')](Object['assign']({},_0x417e9a),{'hash':_0x12407b[a7_0x2110('0x1d')]}));const _0x569ddc=getOutputs(_0x3a6aab[a7_0x2110('0x1f')][a7_0x2110('0x13')],_0x417e9a);if(environment_1[a7_0x2110('0x4c')]){output[a7_0x2110('0x3c')]({'title':'Extracting\x20artifacts','bodyLines':_0x569ddc});}yield _0x4803f5[a7_0x2110('0x1')](_0x12407b[a7_0x2110('0x1d')],_0x444ddf,_0x569ddc);output[a7_0x2110('0x4f')](getCommand(_0x417e9a));process[a7_0x2110('0x3e')][a7_0x2110('0x3b')](_0x444ddf[a7_0x2110('0x22')]);output[a7_0x2110('0xa')]();});}function getCommand(_0x1ad239){const _0x36eed5=_0x1ad239[a7_0x2110('0x2c')]['configuration']?':'+_0x1ad239[a7_0x2110('0x2c')][a7_0x2110('0x2d')]:'';return['nx','run',_0x1ad239[a7_0x2110('0x2c')][a7_0x2110('0x44')]+':'+_0x1ad239['target'][a7_0x2110('0x2c')]+_0x36eed5,(0x0,serializer_overrides_1[a7_0x2110('0x2b')])(_0x1ad239)]['join']('\x20');}const nxCloudDistributedTasksRunner=(_0xd187de,_0x1b14a8,_0x2316be)=>__awaiter(void 0x0,void 0x0,void 0x0,function*(){if(environment_1[a7_0x2110('0x4c')]){output['note']({'title':a7_0x2110('0xb')});}_0x1b14a8['lifeCycle']=new NoopLifeCycle();const _0x1bd8ff=(0x0,environment_1['getRunGroup'])();if(!_0x1bd8ff){(0x0,print_run_group_error_1['printRunGroupError'])();return process[a7_0x2110('0x32')](0x1);}const _0x236526=new e2e_encryption_1['E2EEncryption'](environment_1[a7_0x2110('0x4b')]||_0x1b14a8[a7_0x2110('0x48')]);const _0x36ce70=new error_reporter_api_1[(a7_0x2110('0x42'))](_0x1b14a8);const _0x322bb9=new file_storage_1['FileStorage'](_0x236526,_0x36ce70,!![]);const _0x5d52c3=new Cache(_0x1b14a8);const _0x55a004=new distributed_execution_api_1[(a7_0x2110('0x49'))](_0x1b14a8);try{const _0x3d9e72=getTaskGraph(_0x2316be,_0xd187de,_0x1b14a8);const _0x170421=yield runDistributedExecution(_0x55a004,_0x1b14a8,_0x2316be,_0x322bb9,_0x5d52c3,_0x1bd8ff,_0x3d9e72);if(_0x170421[a7_0x2110('0x41')]===0x0){output['success']({'title':a7_0x2110('0x36'),'bodyLines':['See\x20run\x20details\x20at\x20'+_0x170421[a7_0x2110('0x25')]]});}else{output[a7_0x2110('0x6')]({'title':a7_0x2110('0x40'),'bodyLines':['See\x20run\x20details\x20at\x20'+_0x170421[a7_0x2110('0x25')]]});}yield(0x0,metric_logger_1[a7_0x2110('0xc')])(_0x1b14a8);process[a7_0x2110('0x32')](_0x170421[a7_0x2110('0x41')]);}catch(_0x42b4e1){output['error']({'title':a7_0x2110('0x46'),'bodyLines':[_0x42b4e1[a7_0x2110('0x19')]]});if(_0x42b4e1[a7_0x2110('0x21')]){console['log'](_0x42b4e1[a7_0x2110('0x21')]);}else{console[a7_0x2110('0x47')](_0x42b4e1);}try{yield _0x55a004[a7_0x2110('0x4e')](_0x1bd8ff,a7_0x2110('0x28')+_0x42b4e1[a7_0x2110('0x19')]+'\x22');}finally{process['exit'](0x1);}}});exports[a7_0x2110('0x2')]=nxCloudDistributedTasksRunner;function getTaskGraph(_0x14b43f,_0x1698a1,_0x569fe6){if(_0x14b43f['taskGraph']){return _0x14b43f[a7_0x2110('0x5')];}else{const _0x1d4d8f=JSON[a7_0x2110('0x39')](stripJsonComments((0x0,fs_1['readFileSync'])(workspaceRoot+a7_0x2110('0x53'))['toString']()));return new task_graph_creator_1[(a7_0x2110('0x0'))](_0x14b43f[a7_0x2110('0x1f')],getDefaultDependencyConfigs(_0x1d4d8f,_0x569fe6))[a7_0x2110('0x20')](_0x1698a1);}}function getDefaultDependencyConfigs(_0x757c30,_0x2e73f4){var _0x2d2b59,_0xe4d8b3;const _0x348134=(_0x2d2b59=_0x757c30[a7_0x2110('0x30')])!==null&&_0x2d2b59!==void 0x0?_0x2d2b59:{};const _0x1fc672=_0x2e73f4?(_0xe4d8b3=_0x2e73f4['strictlyOrderedTargets'])!==null&&_0xe4d8b3!==void 0x0?_0xe4d8b3:['build']:[];for(const _0x261de0 of _0x1fc672){_0x348134[_0x261de0]=_0x348134[_0x261de0]||[];_0x348134[_0x261de0][a7_0x2110('0x51')]({'target':_0x261de0,'projects':a7_0x2110('0x33')});}return _0x348134;}