@nrwl/nx-cloud 13.3.0-beta.0 → 13.3.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,239 +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 } = 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', () => cleanupAgentLockfile(lockFilePath));
206
- process.on('SIGINT', () => cleanupAgentLockfile(lockFilePath));
207
- }
208
- function cleanupAgentLockfile(lockFilePath) {
209
- if ((0, fs_1.existsSync)(lockFilePath)) {
210
- (0, fs_1.unlinkSync)(lockFilePath);
211
- }
212
- }
213
- function startAgent() {
214
- return __awaiter(this, void 0, void 0, function* () {
215
- const runGroup = (0, environment_1.getRunGroup)();
216
- if (!runGroup) {
217
- (0, print_run_group_error_1.printRunGroupError)();
218
- return process.exit(1);
219
- }
220
- output.note({
221
- title: 'Starting an agent for running Nx tasks',
222
- });
223
- const options = JSON.parse(stripJsonComments((0, fs_1.readFileSync)('nx.json').toString())).tasksRunnerOptions.default.options;
224
- const agentName = getAgentName();
225
- createAgentLockfile(options, agentName);
226
- const api = new distributed_agent_api_1.DistributedAgentApi(options, runGroup, agentName);
227
- return executeTasks(options, api)
228
- .then((res) => __awaiter(this, void 0, void 0, function* () {
229
- yield (0, metric_logger_1.submitRunMetrics)(options);
230
- return res;
231
- }))
232
- .catch((e) => __awaiter(this, void 0, void 0, function* () {
233
- yield api.completeRunGroupWithError(`Critical Error in Agent: "${e.message}"`);
234
- throw e;
235
- }));
236
- });
237
- }
238
- exports.startAgent = startAgent;
239
- //# sourceMappingURL=distributed-agent.impl.js.map
1
+ const a5_0x3523=['toString','push','map','Distributed\x20Execution\x20Terminated','End\x20all\x20currently\x20running\x20agents,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22,\x20and\x20try\x20again.','Command\x20execution\x20failed\x20(distributed\x20task\x20execution:\x20',').\x20Tasks\x20hashes\x20haven\x27t\x20been\x20recorded.','reset','createNoNewMessagesTimeout','child_process','projects','status','CIRCLE_STAGE','throw','This\x20can\x20also\x20be\x20a\x20false\x20positive\x20caused\x20by\x20agents\x20that\x20did\x20not\x20shut\x20down\x20correctly.','\x20--projects=','forEach','/tasks-hashes-','../../../utilities/waiter','tasks','--configuration=','unlinkSync','Waiting...','NX_AGENT_NAME','VERBOSE_LOGGING','tasksRunnerOptions','cacheDirectory','Critical\x20Error\x20in\x20Agent:\x20\x22','npx\x20nx\x20run-many\x20--target=','startAgent','retryDuring:\x20','Other\x20Nx\x20Cloud\x20Agents\x20Detected','executionId','submitRunMetrics','value','defineProperty','warn','completedStatusCode','readFileSync','getTime','assign','SIGINT','readdirSync','./node_modules/.cache/nx','Starting\x20an\x20agent\x20for\x20running\x20Nx\x20tasks','executionId:\x20','target','completed','message','Executing:\x20\x27','../../../utilities/metric-logger','env','configuration','random','existsSync','../../error/print-run-group-error','length','parse','../../../utilities/environment','CIRCLECI','join','exit','__esModule','writeFileSync','retryDuring','completed:\x20','next','./distributed-agent.api','.lock','criticalErrorMessage','Waiter','strip-json-comments','maxParallel:\x20','floor','apply','projectName','note','../../../utilities/nx-imports','completedTasks','true','done','inherit','number\x20of\x20tasks:\x20','wait','maxParallel','params','then','getRunGroup','Agent\x20'];(function(_0x103250,_0x35237b){const _0x1b0f36=function(_0x5dd8e8){while(--_0x5dd8e8){_0x103250['push'](_0x103250['shift']());}};_0x1b0f36(++_0x35237b);}(a5_0x3523,0x68));const a5_0x1b0f=function(_0x103250,_0x35237b){_0x103250=_0x103250-0x0;let _0x1b0f36=a5_0x3523[_0x103250];return _0x1b0f36;};'use strict';var __awaiter=this&&this['__awaiter']||function(_0x43bc4c,_0x4ab037,_0x13a651,_0x2f09be){function _0x169b5a(_0x4e313a){return _0x4e313a instanceof _0x13a651?_0x4e313a:new _0x13a651(function(_0x448dfd){_0x448dfd(_0x4e313a);});}return new(_0x13a651||(_0x13a651=Promise))(function(_0x5194ca,_0x44e22){function _0x377bf5(_0x4ec634){try{_0x53a72b(_0x2f09be[a5_0x1b0f('0x33')](_0x4ec634));}catch(_0x1987cf){_0x44e22(_0x1987cf);}}function _0x10c03b(_0x38dd6b){try{_0x53a72b(_0x2f09be[a5_0x1b0f('0x57')](_0x38dd6b));}catch(_0x1f09f7){_0x44e22(_0x1f09f7);}}function _0x53a72b(_0x17f3ad){_0x17f3ad[a5_0x1b0f('0x41')]?_0x5194ca(_0x17f3ad[a5_0x1b0f('0x13')]):_0x169b5a(_0x17f3ad[a5_0x1b0f('0x13')])['then'](_0x377bf5,_0x10c03b);}_0x53a72b((_0x2f09be=_0x2f09be[a5_0x1b0f('0x3b')](_0x43bc4c,_0x4ab037||[]))[a5_0x1b0f('0x33')]());});};Object[a5_0x1b0f('0x14')](exports,a5_0x1b0f('0x2f'),{'value':!![]});exports['startAgent']=void 0x0;const child_process_1=require(a5_0x1b0f('0x53'));const stripJsonComments=require(a5_0x1b0f('0x38'));const distributed_agent_api_1=require(a5_0x1b0f('0x34'));const waiter_1=require(a5_0x1b0f('0x3'));const environment_1=require(a5_0x1b0f('0x2b'));const print_run_group_error_1=require(a5_0x1b0f('0x28'));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_0x1b0f('0x23'));const {output}=require(a5_0x1b0f('0x3e'));function executeTasks(_0x50b26b,_0x2bf9af){return __awaiter(this,void 0x0,void 0x0,function*(){let _0x221f3a=0x0;let _0x1dc608=null;const _0x19adc5=(0x0,create_no_new_messages_timeout_1[a5_0x1b0f('0x52')])();const _0x4af86b=new waiter_1[(a5_0x1b0f('0x37'))]();let _0xda5f22=[];const _0xd5a27f=new Date();let _0xb42b3a=![];while(!![]){if(environment_1[a5_0x1b0f('0x9')]){output[a5_0x1b0f('0x3d')]({'title':'Fetching\x20tasks...'});}_0x1dc608=yield _0x2bf9af[a5_0x1b0f('0x4')](_0x1dc608?_0x1dc608[a5_0x1b0f('0x11')]:null,_0x221f3a,_0xda5f22);if(environment_1['VERBOSE_LOGGING']){output[a5_0x1b0f('0x3d')]({'title':'API\x20Response','bodyLines':[a5_0x1b0f('0x32')+_0x1dc608[a5_0x1b0f('0x20')],a5_0x1b0f('0xf')+_0x1dc608['retryDuring'],a5_0x1b0f('0x1e')+_0x1dc608[a5_0x1b0f('0x11')],a5_0x1b0f('0x43')+_0x1dc608[a5_0x1b0f('0x4')][a5_0x1b0f('0x29')],'error:\x20'+_0x1dc608[a5_0x1b0f('0x36')],a5_0x1b0f('0x39')+_0x1dc608[a5_0x1b0f('0x45')]]});}if(_0x1dc608[a5_0x1b0f('0x36')]){output['error']({'title':a5_0x1b0f('0x4d'),'bodyLines':['Error:',_0x1dc608['criticalErrorMessage']]});process[a5_0x1b0f('0x2e')](0x0);}if((_0x1dc608===null||_0x1dc608===void 0x0?void 0x0:_0x1dc608[a5_0x1b0f('0x31')])&&(_0x1dc608===null||_0x1dc608===void 0x0?void 0x0:_0x1dc608[a5_0x1b0f('0x31')])!==0x0&&!_0xb42b3a&&new Date()[a5_0x1b0f('0x18')]()-_0xd5a27f[a5_0x1b0f('0x18')]()>_0x1dc608['retryDuring']){yield _0x4af86b[a5_0x1b0f('0x44')]();continue;}if(_0x1dc608[a5_0x1b0f('0x20')])return;_0x19adc5(_0x1dc608['tasks'][a5_0x1b0f('0x4c')](_0x1a11c9=>_0x1a11c9['taskId'])[a5_0x1b0f('0x2d')](''));if(!_0x1dc608['executionId']){if(environment_1[a5_0x1b0f('0x9')]){output['note']({'title':a5_0x1b0f('0x7')});}yield _0x4af86b['wait']();_0x221f3a=0x0;_0xda5f22=[];continue;}_0x4af86b[a5_0x1b0f('0x51')]();_0xb42b3a=!![];const _0x176dfc=invokeTasksUsingRunMany(_0x50b26b,_0x1dc608[a5_0x1b0f('0x11')],_0x1dc608[a5_0x1b0f('0x4')],_0x1dc608[a5_0x1b0f('0x45')]);_0x221f3a=_0x176dfc[a5_0x1b0f('0x16')];_0xda5f22=_0x176dfc[a5_0x1b0f('0x3f')];}});}function readCompletedTasks(_0x5f7569,_0x248636){const _0x3af59a=a5_0x1b0f('0x4f')+_0x248636+a5_0x1b0f('0x50');let _0x592719;try{const _0x4f310e=_0x5f7569[a5_0x1b0f('0xb')]||a5_0x1b0f('0x1c');const _0x149d8b=_0x4f310e+a5_0x1b0f('0x2')+_0x248636;_0x592719=JSON[a5_0x1b0f('0x2a')]((0x0,fs_1[a5_0x1b0f('0x17')])(_0x149d8b)['toString']());(0x0,fs_1[a5_0x1b0f('0x6')])(_0x149d8b);}catch(_0x539bc5){throw new Error(_0x3af59a);}if(_0x592719[a5_0x1b0f('0x29')]==0x0){throw new Error(_0x3af59a);}return _0x592719;}function invokeTasksUsingRunMany(_0x4c8cea,_0x37b003,_0x352297,_0x15fcd4){let _0x397087=0x0;const _0x21c215=[];for(const _0x158c98 of groupByTarget(_0x352297)){const _0x408984=_0x158c98[a5_0x1b0f('0x25')]?a5_0x1b0f('0x5')+_0x158c98[a5_0x1b0f('0x25')]:'';const _0x5582fa=_0x15fcd4>0x1?'\x20--parallel\x20--max-parallel='+_0x15fcd4:'';const _0x4b13f7=a5_0x1b0f('0xd')+_0x158c98[a5_0x1b0f('0x1f')]+'\x20'+_0x408984+a5_0x1b0f('0x0')+_0x158c98[a5_0x1b0f('0x54')][a5_0x1b0f('0x2d')](',')+'\x20'+_0x158c98['params']+_0x5582fa;if(environment_1[a5_0x1b0f('0x9')]){output[a5_0x1b0f('0x3d')]({'title':a5_0x1b0f('0x22')+_0x4b13f7+'\x27'});}try{(0x0,child_process_1['execSync'])(_0x4b13f7,{'stdio':['inherit','inherit',a5_0x1b0f('0x42')],'env':Object[a5_0x1b0f('0x19')](Object[a5_0x1b0f('0x19')]({},process[a5_0x1b0f('0x24')]),{'NX_CACHE_FAILURES':a5_0x1b0f('0x40'),'NX_CLOUD_DISTRIBUTED_EXECUTION_ID':_0x37b003})});}catch(_0x512df0){if(_0x512df0[a5_0x1b0f('0x55')]===environment_1['DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE']){throw _0x512df0;}else{_0x397087=0x1;}}finally{_0x21c215[a5_0x1b0f('0x4b')](...readCompletedTasks(_0x4c8cea,_0x37b003));}}return{'completedStatusCode':_0x397087,'completedTasks':_0x21c215};}function groupByTarget(_0x35eac8){const _0x119770=[];_0x35eac8[a5_0x1b0f('0x1')](_0xf3eb97=>{const _0x26b8ac=_0x119770['find'](_0x1347b8=>_0x1347b8[a5_0x1b0f('0x1f')]===_0xf3eb97['target']&&_0x1347b8[a5_0x1b0f('0x25')]===_0xf3eb97[a5_0x1b0f('0x25')]);if(_0x26b8ac){_0x26b8ac[a5_0x1b0f('0x54')][a5_0x1b0f('0x4b')](_0xf3eb97[a5_0x1b0f('0x3c')]);}else{_0x119770[a5_0x1b0f('0x4b')]({'target':_0xf3eb97[a5_0x1b0f('0x1f')],'projects':[_0xf3eb97[a5_0x1b0f('0x3c')]],'params':_0xf3eb97[a5_0x1b0f('0x46')],'configuration':_0xf3eb97[a5_0x1b0f('0x25')]});}});return _0x119770;}function getAgentName(){if(process['env'][a5_0x1b0f('0x8')]!==undefined){return process[a5_0x1b0f('0x24')][a5_0x1b0f('0x8')];}else if(process[a5_0x1b0f('0x24')][a5_0x1b0f('0x2c')]!==undefined){return process[a5_0x1b0f('0x24')][a5_0x1b0f('0x56')];}else{return a5_0x1b0f('0x49')+Math[a5_0x1b0f('0x3a')](Math[a5_0x1b0f('0x26')]()*0x186a0);}}function createAgentLockfile(_0x4deb8f,_0x335832){const _0x170570=_0x4deb8f['cacheDirectory']||a5_0x1b0f('0x1c');const _0x19217f=_0x170570+'/lockfiles';const _0x5d4e1b=_0x19217f+'/'+_0x335832+'.lock';if(!(0x0,fs_1['existsSync'])(_0x19217f)){(0x0,fs_1['mkdirSync'])(_0x19217f,{'recursive':!![]});}const _0x30132=(0x0,fs_1[a5_0x1b0f('0x1b')])(_0x19217f);if(_0x30132[a5_0x1b0f('0x29')]){if(_0x30132['includes'](_0x335832+a5_0x1b0f('0x35'))){output['error']({'title':'Duplicate\x20Agent\x20ID\x20Detected','bodyLines':['We\x20have\x20detected\x20another\x20agent\x20with\x20this\x20ID\x20running\x20in\x20this\x20workspace.\x20This\x20should\x20not\x20happen.','',a5_0x1b0f('0x4e')]});process[a5_0x1b0f('0x2e')](0x1);}output[a5_0x1b0f('0x15')]({'title':a5_0x1b0f('0x10'),'bodyLines':['We\x20have\x20detected\x20other\x20agents\x20running\x20in\x20this\x20workspace.\x20This\x20can\x20cause\x20unexpected\x20behavior.','',a5_0x1b0f('0x58'),'If\x20you\x20believe\x20this\x20is\x20the\x20case,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22.']});}(0x0,fs_1[a5_0x1b0f('0x30')])(_0x5d4e1b,'');process['on'](a5_0x1b0f('0x2e'),()=>cleanupAgentLockfile(_0x5d4e1b));process['on'](a5_0x1b0f('0x1a'),()=>cleanupAgentLockfile(_0x5d4e1b));}function cleanupAgentLockfile(_0x117180){if((0x0,fs_1[a5_0x1b0f('0x27')])(_0x117180)){(0x0,fs_1[a5_0x1b0f('0x6')])(_0x117180);}}function startAgent(){return __awaiter(this,void 0x0,void 0x0,function*(){const _0xc17d6d=(0x0,environment_1[a5_0x1b0f('0x48')])();if(!_0xc17d6d){(0x0,print_run_group_error_1['printRunGroupError'])();return process[a5_0x1b0f('0x2e')](0x1);}output[a5_0x1b0f('0x3d')]({'title':a5_0x1b0f('0x1d')});const _0x335bc4=JSON[a5_0x1b0f('0x2a')](stripJsonComments((0x0,fs_1['readFileSync'])('nx.json')[a5_0x1b0f('0x4a')]()))[a5_0x1b0f('0xa')]['default']['options'];const _0x51932a=getAgentName();createAgentLockfile(_0x335bc4,_0x51932a);const _0xebb9ab=new distributed_agent_api_1['DistributedAgentApi'](_0x335bc4,_0xc17d6d,_0x51932a);return executeTasks(_0x335bc4,_0xebb9ab)[a5_0x1b0f('0x47')](_0x3188e9=>__awaiter(this,void 0x0,void 0x0,function*(){yield(0x0,metric_logger_1[a5_0x1b0f('0x12')])(_0x335bc4);return _0x3188e9;}))['catch'](_0x53617e=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0xebb9ab['completeRunGroupWithError'](a5_0x1b0f('0xc')+_0x53617e[a5_0x1b0f('0x21')]+'\x22');throw _0x53617e;}));});}exports[a5_0x1b0f('0xe')]=startAgent;
@@ -1,130 +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 { 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
1
+ const a6_0x263a=['false','join','parallel','recordMetric','../../../utilities/environment','__esModule','error','axiosException','getBranch','map','apiAxiosInstance','target','defineProperty','../../../utilities/metric-logger','axiosMultipleTries','data','hash','stopAgentsOnFailure','project','next','dteStatus','message','maxParallel','/nx-cloud/executions/start','createStartRequest','RUNNER_FAILURE_PERF_ENTRY','agentCount','configuration','parseCommand','../../../utilities/axios','/nx-cloud/executions/status','../../../utilities/nx-imports','NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT','done','true','then','completeRunGroup','post','createMetricRecorder','throw','apply','createApiAxiosInstance','completeRunGroupWithError','mapRespToPerfEntry','response','status','/nx-cloud/executions/complete-run-group','value','enabled','dteStart','DistributedExecutionApi','NX_CLOUD_DISTRIBUTED_EXECUTION_STOP_AGENTS_ON_FAILURE','overrides'];(function(_0x4503a9,_0x263a8d){const _0x3127b4=function(_0x54906f){while(--_0x54906f){_0x4503a9['push'](_0x4503a9['shift']());}};_0x3127b4(++_0x263a8d);}(a6_0x263a,0x186));const a6_0x3127=function(_0x4503a9,_0x263a8d){_0x4503a9=_0x4503a9-0x0;let _0x3127b4=a6_0x263a[_0x4503a9];return _0x3127b4;};'use strict';var __awaiter=this&&this['__awaiter']||function(_0x179778,_0x4151f9,_0x37acd7,_0xcb38f7){function _0x2257ba(_0x459b96){return _0x459b96 instanceof _0x37acd7?_0x459b96:new _0x37acd7(function(_0x242b60){_0x242b60(_0x459b96);});}return new(_0x37acd7||(_0x37acd7=Promise))(function(_0x21b37f,_0x12e9f9){function _0x4ca5ea(_0x2f1ba0){try{_0x1fe5e4(_0xcb38f7[a6_0x3127('0x0')](_0x2f1ba0));}catch(_0x58e0bd){_0x12e9f9(_0x58e0bd);}}function _0x453839(_0x3c2172){try{_0x1fe5e4(_0xcb38f7[a6_0x3127('0x14')](_0x3c2172));}catch(_0x51285a){_0x12e9f9(_0x51285a);}}function _0x1fe5e4(_0x4068aa){_0x4068aa[a6_0x3127('0xe')]?_0x21b37f(_0x4068aa[a6_0x3127('0x1c')]):_0x2257ba(_0x4068aa[a6_0x3127('0x1c')])[a6_0x3127('0x10')](_0x4ca5ea,_0x453839);}_0x1fe5e4((_0xcb38f7=_0xcb38f7[a6_0x3127('0x15')](_0x179778,_0x4151f9||[]))[a6_0x3127('0x0')]());});};Object[a6_0x3127('0x2e')](exports,a6_0x3127('0x27'),{'value':!![]});exports[a6_0x3127('0x5')]=exports[a6_0x3127('0x1f')]=void 0x0;const axios_1=require(a6_0x3127('0xa'));const environment_1=require(a6_0x3127('0x26'));const metric_logger_1=require(a6_0x3127('0x2f'));const {output,unparse}=require(a6_0x3127('0xc'));class DistributedExecutionApi{constructor(_0x1b1504){this[a6_0x3127('0x2c')]=(0x0,axios_1[a6_0x3127('0x16')])(_0x1b1504);}['start'](_0x49f161){var _0x1f8b08;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x1c1362=(0x0,metric_logger_1[a6_0x3127('0x13')])(a6_0x3127('0x1e'));let _0x373978;try{_0x373978=yield(0x0,axios_1['axiosMultipleTries'])(()=>this['apiAxiosInstance'][a6_0x3127('0x12')](a6_0x3127('0x4'),_0x49f161));_0x1c1362['recordMetric']((0x0,metric_logger_1[a6_0x3127('0x18')])(_0x373978));}catch(_0x1a1789){_0x1c1362[a6_0x3127('0x25')](((_0x1f8b08=_0x1a1789===null||_0x1a1789===void 0x0?void 0x0:_0x1a1789['axiosException'])===null||_0x1f8b08===void 0x0?void 0x0:_0x1f8b08[a6_0x3127('0x19')])?(0x0,metric_logger_1[a6_0x3127('0x18')])(_0x1a1789[a6_0x3127('0x29')][a6_0x3127('0x19')]):metric_logger_1[a6_0x3127('0x6')]);throw _0x1a1789;}if(!_0x373978['data'][a6_0x3127('0x1d')]){throw new Error('Workspace\x20is\x20disabled.\x20Cannot\x20perform\x20distributed\x20task\x20executions.');}if(_0x373978[a6_0x3127('0x31')]['error']){throw new Error(_0x373978['data'][a6_0x3127('0x28')]);}return _0x373978[a6_0x3127('0x31')]['id'];});}[a6_0x3127('0x1a')](_0x4ea464){var _0x3f5ef4;return __awaiter(this,void 0x0,void 0x0,function*(){const _0xdb540a=(0x0,metric_logger_1['createMetricRecorder'])(a6_0x3127('0x1'));try{const _0x57339c=yield(0x0,axios_1[a6_0x3127('0x30')])(()=>this[a6_0x3127('0x2c')]['post'](a6_0x3127('0xb'),{'id':_0x4ea464}));_0xdb540a[a6_0x3127('0x25')]((0x0,metric_logger_1[a6_0x3127('0x18')])(_0x57339c));return _0x57339c[a6_0x3127('0x31')];}catch(_0x40b0cd){_0xdb540a[a6_0x3127('0x25')](((_0x3f5ef4=_0x40b0cd===null||_0x40b0cd===void 0x0?void 0x0:_0x40b0cd[a6_0x3127('0x29')])===null||_0x3f5ef4===void 0x0?void 0x0:_0x3f5ef4[a6_0x3127('0x19')])?(0x0,metric_logger_1[a6_0x3127('0x18')])(_0x40b0cd[a6_0x3127('0x29')]['response']):metric_logger_1[a6_0x3127('0x6')]);output['error']({'title':_0x40b0cd[a6_0x3127('0x2')]});process['exit'](0x1);}});}[a6_0x3127('0x17')](_0x47bf02,_0x15e3a1){var _0x54ccab;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x1464aa=(0x0,metric_logger_1[a6_0x3127('0x13')])(a6_0x3127('0x11'));try{const _0x1ccbec=yield(0x0,axios_1[a6_0x3127('0x30')])(()=>this[a6_0x3127('0x2c')]['post'](a6_0x3127('0x1b'),{'runGroup':_0x47bf02,'criticalErrorMessage':_0x15e3a1}),0x3);_0x1464aa['recordMetric']((0x0,metric_logger_1[a6_0x3127('0x18')])(_0x1ccbec));}catch(_0xb908c3){_0x1464aa['recordMetric'](((_0x54ccab=_0xb908c3===null||_0xb908c3===void 0x0?void 0x0:_0xb908c3[a6_0x3127('0x29')])===null||_0x54ccab===void 0x0?void 0x0:_0x54ccab[a6_0x3127('0x19')])?(0x0,metric_logger_1[a6_0x3127('0x18')])(_0xb908c3[a6_0x3127('0x29')]['response']):metric_logger_1[a6_0x3127('0x6')]);}});}}exports[a6_0x3127('0x1f')]=DistributedExecutionApi;function createStartRequest(_0x5057fa,_0x73533c,_0x5bdb68){const _0x2fb28e=_0x73533c[a6_0x3127('0x2b')](_0x22a5c8=>{return _0x22a5c8[a6_0x3127('0x2b')](_0x5dcce2=>{return{'taskId':_0x5dcce2['id'],'hash':_0x5dcce2[a6_0x3127('0x32')],'projectName':_0x5dcce2[a6_0x3127('0x2d')][a6_0x3127('0x34')],'target':_0x5dcce2[a6_0x3127('0x2d')]['target'],'configuration':_0x5dcce2[a6_0x3127('0x2d')][a6_0x3127('0x8')]||null,'params':unparse(_0x5dcce2[a6_0x3127('0x21')])[a6_0x3127('0x23')]('\x20')};});});const _0x22d5c5={'command':(0x0,environment_1[a6_0x3127('0x9')])(),'branch':(0x0,environment_1[a6_0x3127('0x2a')])(),'runGroup':_0x5057fa,'tasks':_0x2fb28e,'maxParallel':calculateMaxParallel(_0x5bdb68)};if(environment_1[a6_0x3127('0xd')]){_0x22d5c5[a6_0x3127('0x7')]=environment_1[a6_0x3127('0xd')];}if(!environment_1[a6_0x3127('0x20')]){_0x22d5c5[a6_0x3127('0x33')]=![];}return _0x22d5c5;}exports[a6_0x3127('0x5')]=createStartRequest;function calculateMaxParallel(_0x27f5ed){if(_0x27f5ed[a6_0x3127('0x24')]===a6_0x3127('0x22')||_0x27f5ed[a6_0x3127('0x24')]===![]){return 0x1;}else if(_0x27f5ed[a6_0x3127('0x24')]===a6_0x3127('0xf')||_0x27f5ed[a6_0x3127('0x24')]===!![]){return Number(_0x27f5ed[a6_0x3127('0x3')]||0x3);}else if(_0x27f5ed[a6_0x3127('0x24')]===undefined){return _0x27f5ed[a6_0x3127('0x3')]?Number(_0x27f5ed['maxParallel']):0x3;}else{return Number(_0x27f5ed[a6_0x3127('0x24')])||0x3;}}