@nrwl/nx-cloud 14.1.2-beta.2 → 14.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core/api/error-reporter.api.js +1 -36
- package/lib/core/api/run-group.api.js +1 -65
- package/lib/core/runners/cloud-enabled/cloud-enabled-life-cycle.js +1 -138
- package/lib/core/runners/cloud-enabled/cloud-enabled.runner.js +1 -169
- package/lib/core/runners/cloud-enabled/cloud-remote-cache.js +1 -113
- package/lib/core/runners/cloud-enabled/cloud-run.api.js +1 -166
- package/lib/core/runners/distributed-agent/distributed-agent.api.js +1 -79
- package/lib/core/runners/distributed-agent/distributed-agent.impl.js +1 -240
- package/lib/core/runners/distributed-execution/distributed-execution.api.js +1 -131
- package/lib/core/runners/distributed-execution/distributed-execution.runner.js +1 -206
- package/lib/core/runners/distributed-execution/split-task-graph-into-stages.js +1 -37
- package/lib/core/runners/distributed-execution/task-graph-creator.js +1 -77
- package/lib/utilities/nx-imports.js +48 -37
- package/lib/utilities/nx-imports.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,166 +1 @@
|
|
|
1
|
-
|
|
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.CloudRunApi = void 0;
|
|
13
|
-
const axios_1 = require("../../../utilities/axios");
|
|
14
|
-
const environment_1 = require("../../../utilities/environment");
|
|
15
|
-
const fs_1 = require("fs");
|
|
16
|
-
const zlib_1 = require("zlib");
|
|
17
|
-
const util_1 = require("util");
|
|
18
|
-
const metric_logger_1 = require("../../../utilities/metric-logger");
|
|
19
|
-
const { output } = require('../../../utilities/nx-imports');
|
|
20
|
-
class CloudRunApi {
|
|
21
|
-
constructor(messages, runContext, options, machineInfo) {
|
|
22
|
-
this.messages = messages;
|
|
23
|
-
this.runContext = runContext;
|
|
24
|
-
this.machineInfo = machineInfo;
|
|
25
|
-
this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options);
|
|
26
|
-
}
|
|
27
|
-
startRun(distributedExecutionId, hashes) {
|
|
28
|
-
var _a;
|
|
29
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
const recorder = (0, metric_logger_1.createMetricRecorder)('startRun');
|
|
31
|
-
try {
|
|
32
|
-
const request = {
|
|
33
|
-
meta: {
|
|
34
|
-
nxCloudVersion: this.nxCloudVersion(),
|
|
35
|
-
},
|
|
36
|
-
branch: (0, environment_1.getBranch)(),
|
|
37
|
-
runGroup: (0, environment_1.getRunGroup)(),
|
|
38
|
-
distributedExecutionId,
|
|
39
|
-
hashes,
|
|
40
|
-
};
|
|
41
|
-
if (environment_1.VERBOSE_LOGGING) {
|
|
42
|
-
output.note({
|
|
43
|
-
title: 'RunStart',
|
|
44
|
-
bodyLines: ['\n' + JSON.stringify(request, null, 2)],
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/runs/start', request));
|
|
48
|
-
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
|
|
49
|
-
if (resp.data && resp.data.message) {
|
|
50
|
-
this.messages.message = resp.data.message;
|
|
51
|
-
}
|
|
52
|
-
if (!resp.data || !resp.data.urls) {
|
|
53
|
-
this.messages.apiError = `Invalid Nx Cloud response: ${JSON.stringify(resp.data)}`;
|
|
54
|
-
return {};
|
|
55
|
-
}
|
|
56
|
-
return resp.data.urls;
|
|
57
|
-
}
|
|
58
|
-
catch (e) {
|
|
59
|
-
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
60
|
-
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
|
|
61
|
-
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
62
|
-
this.messages.apiError = this.messages.extractErrorMessage(e, 'api');
|
|
63
|
-
return {};
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
createReqBody(run, tasks) {
|
|
68
|
-
const uncompressedReqBody = {
|
|
69
|
-
meta: {
|
|
70
|
-
nxCloudVersion: this.nxCloudVersion(),
|
|
71
|
-
},
|
|
72
|
-
tasks,
|
|
73
|
-
run: run,
|
|
74
|
-
machineInfo: this.machineInfo,
|
|
75
|
-
};
|
|
76
|
-
return JSON.stringify(uncompressedReqBody);
|
|
77
|
-
}
|
|
78
|
-
endRun(run, tasks) {
|
|
79
|
-
var _a, _b;
|
|
80
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
// API is not working, don't make the end request
|
|
82
|
-
if (this.messages.apiError)
|
|
83
|
-
return false;
|
|
84
|
-
let uncompressedBodyString = this.createReqBody(run, tasks);
|
|
85
|
-
// if the req body is > 20mb, remove hashDetails
|
|
86
|
-
if (uncompressedBodyString.length > 20 * 1000 * 1000) {
|
|
87
|
-
uncompressedBodyString = this.createReqBody(run, tasks.map((t) => (Object.assign(Object.assign({}, t), { hashDetails: undefined }))));
|
|
88
|
-
}
|
|
89
|
-
const uncompressedBuffer = Buffer.from(uncompressedBodyString);
|
|
90
|
-
const compressedBuffer = yield (0, util_1.promisify)(zlib_1.gzip)(uncompressedBuffer);
|
|
91
|
-
const recorder = (0, metric_logger_1.createMetricRecorder)('endRun');
|
|
92
|
-
try {
|
|
93
|
-
if (environment_1.VERBOSE_LOGGING) {
|
|
94
|
-
const t = tasks.map((tt) => {
|
|
95
|
-
return Object.assign(Object.assign({}, tt), { terminalOutput: tt.terminalOutput
|
|
96
|
-
? `${tt.terminalOutput.slice(0, 20)}...`
|
|
97
|
-
: undefined });
|
|
98
|
-
});
|
|
99
|
-
output.note({
|
|
100
|
-
title: 'RunEnd. Completed tasks',
|
|
101
|
-
bodyLines: ['\n' + JSON.stringify(t, null, 2)],
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/runs/end', compressedBuffer, {
|
|
105
|
-
headers: Object.assign(Object.assign({}, this.apiAxiosInstance.defaults.headers), { 'Content-Encoding': 'gzip', 'Content-Type': 'application/octet-stream' }),
|
|
106
|
-
}));
|
|
107
|
-
if (resp) {
|
|
108
|
-
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
|
|
109
|
-
if (resp.data && resp.data.runUrl && resp.data.status === 'success') {
|
|
110
|
-
this.runContext.runUrl = resp.data.runUrl;
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
if (resp.data && resp.data.status) {
|
|
114
|
-
this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data.message)}`;
|
|
115
|
-
}
|
|
116
|
-
else if (resp.data && typeof resp.data === 'string') {
|
|
117
|
-
if (resp.data !== 'success') {
|
|
118
|
-
this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data)}`;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data)}`;
|
|
123
|
-
}
|
|
124
|
-
if (environment_1.VERBOSE_LOGGING) {
|
|
125
|
-
output.note({
|
|
126
|
-
title: 'Invalid end run response',
|
|
127
|
-
bodyLines: [JSON.stringify(resp.data, null, 2)],
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
output.error({
|
|
133
|
-
title: 'Nx Cloud: Unknown Error Occurred',
|
|
134
|
-
bodyLines: [
|
|
135
|
-
'Run completion responded with `undefined`.',
|
|
136
|
-
'Run Details:',
|
|
137
|
-
JSON.stringify(run, null, 2),
|
|
138
|
-
'Stack Trace:',
|
|
139
|
-
JSON.stringify(new Error().stack, null, 2),
|
|
140
|
-
],
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
catch (ee) {
|
|
146
|
-
recorder.recordMetric(((_a = ee === null || ee === void 0 ? void 0 : ee.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
147
|
-
? (0, metric_logger_1.mapRespToPerfEntry)(ee.axiosException.response)
|
|
148
|
-
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
149
|
-
const e = (_b = ee.axiosException) !== null && _b !== void 0 ? _b : ee;
|
|
150
|
-
this.messages.apiError = this.messages.extractErrorMessage(e, 'api');
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
nxCloudVersion() {
|
|
156
|
-
try {
|
|
157
|
-
const v = JSON.parse((0, fs_1.readFileSync)(`package.json`).toString());
|
|
158
|
-
return v.devDependencies['@nrwl/nx-cloud'];
|
|
159
|
-
}
|
|
160
|
-
catch (e) {
|
|
161
|
-
return 'unknown';
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
exports.CloudRunApi = CloudRunApi;
|
|
166
|
-
//# sourceMappingURL=cloud-run.api.js.map
|
|
1
|
+
const a3_0x22ca=['...','assign','from','Stack\x20Trace:','throw','api','../../../utilities/nx-imports','application/octet-stream','startRun','string','headers','RUNNER_FAILURE_PERF_ENTRY','__esModule','/nx-cloud/runs/end','stringify','Run\x20completion\x20responded\x20with\x20`undefined`.','Invalid\x20end\x20run\x20response:\x20','next','gzip','machineInfo','../../../utilities/environment','Invalid\x20Nx\x20Cloud\x20response:\x20','then','extractErrorMessage','package.json','zlib','stack','toString','response','../../../utilities/axios','parse','apiError','VERBOSE_LOGGING','defineProperty','slice','endRun','value','getRunGroup','CloudRunApi','note','createApiAxiosInstance','RunEnd.\x20Completed\x20tasks','Invalid\x20end\x20run\x20response','terminalOutput','apiAxiosInstance','recordMetric','data','Run\x20Details:','success','mapRespToPerfEntry','runUrl','axiosMultipleTries','promisify','devDependencies','unknown','Nx\x20Cloud:\x20Unknown\x20Error\x20Occurred','createMetricRecorder','post','nxCloudVersion','createReqBody','map','messages','defaults','error','axiosException','__awaiter','urls','runContext','message','done'];(function(_0x223aa2,_0x22ca7a){const _0x1f8ba7=function(_0x143f8d){while(--_0x143f8d){_0x223aa2['push'](_0x223aa2['shift']());}};_0x1f8ba7(++_0x22ca7a);}(a3_0x22ca,0xf3));const a3_0x1f8b=function(_0x223aa2,_0x22ca7a){_0x223aa2=_0x223aa2-0x0;let _0x1f8ba7=a3_0x22ca[_0x223aa2];return _0x1f8ba7;};'use strict';var __awaiter=this&&this[a3_0x1f8b('0x20')]||function(_0x22c94f,_0x4dc877,_0x41972e,_0x31f693){function _0x46b06a(_0x178b64){return _0x178b64 instanceof _0x41972e?_0x178b64:new _0x41972e(function(_0x51867c){_0x51867c(_0x178b64);});}return new(_0x41972e||(_0x41972e=Promise))(function(_0x4176f8,_0x1eb8bd){function _0x5d4c49(_0x3cab75){try{_0x1488f2(_0x31f693['next'](_0x3cab75));}catch(_0x49fcdc){_0x1eb8bd(_0x49fcdc);}}function _0x5cb9f4(_0x4f861b){try{_0x1488f2(_0x31f693[a3_0x1f8b('0x29')](_0x4f861b));}catch(_0x15717f){_0x1eb8bd(_0x15717f);}}function _0x1488f2(_0x31af08){_0x31af08[a3_0x1f8b('0x24')]?_0x4176f8(_0x31af08['value']):_0x46b06a(_0x31af08[a3_0x1f8b('0x3')])[a3_0x1f8b('0x3b')](_0x5d4c49,_0x5cb9f4);}_0x1488f2((_0x31f693=_0x31f693['apply'](_0x22c94f,_0x4dc877||[]))[a3_0x1f8b('0x36')]());});};Object[a3_0x1f8b('0x0')](exports,a3_0x1f8b('0x31'),{'value':!![]});exports['CloudRunApi']=void 0x0;const axios_1=require(a3_0x1f8b('0x42'));const environment_1=require(a3_0x1f8b('0x39'));const fs_1=require('fs');const zlib_1=require(a3_0x1f8b('0x3e'));const util_1=require('util');const metric_logger_1=require('../../../utilities/metric-logger');const {output}=require(a3_0x1f8b('0x2b'));class CloudRunApi{constructor(_0x5315db,_0x1b32d4,_0x5cf3ed,_0x5bf311){this[a3_0x1f8b('0x1c')]=_0x5315db;this[a3_0x1f8b('0x22')]=_0x1b32d4;this['machineInfo']=_0x5bf311;this[a3_0x1f8b('0xb')]=(0x0,axios_1[a3_0x1f8b('0x7')])(_0x5cf3ed);}[a3_0x1f8b('0x2d')](_0x25d26f,_0x64afe4){var _0x48066c;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x4f96cf=(0x0,metric_logger_1['createMetricRecorder'])(a3_0x1f8b('0x2d'));try{const _0x2ff0cd={'meta':{'nxCloudVersion':this[a3_0x1f8b('0x19')]()},'branch':(0x0,environment_1['getBranch'])(),'runGroup':(0x0,environment_1[a3_0x1f8b('0x4')])(),'distributedExecutionId':_0x25d26f,'hashes':_0x64afe4};if(environment_1['VERBOSE_LOGGING']){output[a3_0x1f8b('0x6')]({'title':'RunStart','bodyLines':['\x0a'+JSON[a3_0x1f8b('0x33')](_0x2ff0cd,null,0x2)]});}const _0x523374=yield(0x0,axios_1[a3_0x1f8b('0x12')])(()=>this[a3_0x1f8b('0xb')]['post']('/nx-cloud/runs/start',_0x2ff0cd));_0x4f96cf['recordMetric']((0x0,metric_logger_1[a3_0x1f8b('0x10')])(_0x523374));if(_0x523374['data']&&_0x523374[a3_0x1f8b('0xd')]['message']){this[a3_0x1f8b('0x1c')][a3_0x1f8b('0x23')]=_0x523374[a3_0x1f8b('0xd')][a3_0x1f8b('0x23')];}if(!_0x523374['data']||!_0x523374[a3_0x1f8b('0xd')][a3_0x1f8b('0x21')]){this[a3_0x1f8b('0x1c')][a3_0x1f8b('0x44')]=a3_0x1f8b('0x3a')+JSON[a3_0x1f8b('0x33')](_0x523374[a3_0x1f8b('0xd')]);return{};}return _0x523374[a3_0x1f8b('0xd')][a3_0x1f8b('0x21')];}catch(_0x40b80c){_0x4f96cf[a3_0x1f8b('0xc')](((_0x48066c=_0x40b80c===null||_0x40b80c===void 0x0?void 0x0:_0x40b80c[a3_0x1f8b('0x1f')])===null||_0x48066c===void 0x0?void 0x0:_0x48066c[a3_0x1f8b('0x41')])?(0x0,metric_logger_1[a3_0x1f8b('0x10')])(_0x40b80c[a3_0x1f8b('0x1f')]['response']):metric_logger_1['RUNNER_FAILURE_PERF_ENTRY']);this['messages'][a3_0x1f8b('0x44')]=this['messages'][a3_0x1f8b('0x3c')](_0x40b80c,'api');return{};}});}[a3_0x1f8b('0x1a')](_0x35040f,_0x5625da){const _0x51dfa2={'meta':{'nxCloudVersion':this[a3_0x1f8b('0x19')]()},'tasks':_0x5625da,'run':_0x35040f,'machineInfo':this[a3_0x1f8b('0x38')]};return JSON['stringify'](_0x51dfa2);}[a3_0x1f8b('0x2')](_0x27ce54,_0x18772e){var _0xd0937e,_0x1f662d;return __awaiter(this,void 0x0,void 0x0,function*(){if(this[a3_0x1f8b('0x1c')][a3_0x1f8b('0x44')])return![];let _0x529eeb=this['createReqBody'](_0x27ce54,_0x18772e);if(_0x529eeb['length']>0x14*0x3e8*0x3e8){_0x529eeb=this['createReqBody'](_0x27ce54,_0x18772e[a3_0x1f8b('0x1b')](_0x7ad001=>Object[a3_0x1f8b('0x26')](Object[a3_0x1f8b('0x26')]({},_0x7ad001),{'hashDetails':undefined})));}const _0x1ec9c0=Buffer[a3_0x1f8b('0x27')](_0x529eeb);const _0x9ec2e4=yield(0x0,util_1[a3_0x1f8b('0x13')])(zlib_1[a3_0x1f8b('0x37')])(_0x1ec9c0);const _0x63d4a0=(0x0,metric_logger_1[a3_0x1f8b('0x17')])('endRun');try{if(environment_1[a3_0x1f8b('0x45')]){const _0x4a70b2=_0x18772e[a3_0x1f8b('0x1b')](_0x4314e7=>{return Object[a3_0x1f8b('0x26')](Object[a3_0x1f8b('0x26')]({},_0x4314e7),{'terminalOutput':_0x4314e7[a3_0x1f8b('0xa')]?_0x4314e7[a3_0x1f8b('0xa')][a3_0x1f8b('0x1')](0x0,0x14)+a3_0x1f8b('0x25'):undefined});});output[a3_0x1f8b('0x6')]({'title':a3_0x1f8b('0x8'),'bodyLines':['\x0a'+JSON['stringify'](_0x4a70b2,null,0x2)]});}const _0x546be0=yield(0x0,axios_1[a3_0x1f8b('0x12')])(()=>this['apiAxiosInstance'][a3_0x1f8b('0x18')](a3_0x1f8b('0x32'),_0x9ec2e4,{'headers':Object['assign'](Object['assign']({},this[a3_0x1f8b('0xb')][a3_0x1f8b('0x1d')][a3_0x1f8b('0x2f')]),{'Content-Encoding':a3_0x1f8b('0x37'),'Content-Type':a3_0x1f8b('0x2c')})}));if(_0x546be0){_0x63d4a0[a3_0x1f8b('0xc')]((0x0,metric_logger_1[a3_0x1f8b('0x10')])(_0x546be0));if(_0x546be0[a3_0x1f8b('0xd')]&&_0x546be0[a3_0x1f8b('0xd')][a3_0x1f8b('0x11')]&&_0x546be0[a3_0x1f8b('0xd')]['status']===a3_0x1f8b('0xf')){this[a3_0x1f8b('0x22')][a3_0x1f8b('0x11')]=_0x546be0[a3_0x1f8b('0xd')][a3_0x1f8b('0x11')];return!![];}if(_0x546be0[a3_0x1f8b('0xd')]&&_0x546be0[a3_0x1f8b('0xd')]['status']){this[a3_0x1f8b('0x1c')][a3_0x1f8b('0x44')]=a3_0x1f8b('0x35')+JSON[a3_0x1f8b('0x33')](_0x546be0[a3_0x1f8b('0xd')][a3_0x1f8b('0x23')]);}else if(_0x546be0[a3_0x1f8b('0xd')]&&typeof _0x546be0[a3_0x1f8b('0xd')]===a3_0x1f8b('0x2e')){if(_0x546be0['data']!==a3_0x1f8b('0xf')){this['messages'][a3_0x1f8b('0x44')]='Invalid\x20end\x20run\x20response:\x20'+JSON[a3_0x1f8b('0x33')](_0x546be0[a3_0x1f8b('0xd')]);}}else{this[a3_0x1f8b('0x1c')][a3_0x1f8b('0x44')]=a3_0x1f8b('0x35')+JSON[a3_0x1f8b('0x33')](_0x546be0[a3_0x1f8b('0xd')]);}if(environment_1[a3_0x1f8b('0x45')]){output[a3_0x1f8b('0x6')]({'title':a3_0x1f8b('0x9'),'bodyLines':[JSON['stringify'](_0x546be0[a3_0x1f8b('0xd')],null,0x2)]});}}else{output[a3_0x1f8b('0x1e')]({'title':a3_0x1f8b('0x16'),'bodyLines':[a3_0x1f8b('0x34'),a3_0x1f8b('0xe'),JSON['stringify'](_0x27ce54,null,0x2),a3_0x1f8b('0x28'),JSON[a3_0x1f8b('0x33')](new Error()[a3_0x1f8b('0x3f')],null,0x2)]});}return![];}catch(_0x368e7a){_0x63d4a0[a3_0x1f8b('0xc')](((_0xd0937e=_0x368e7a===null||_0x368e7a===void 0x0?void 0x0:_0x368e7a[a3_0x1f8b('0x1f')])===null||_0xd0937e===void 0x0?void 0x0:_0xd0937e[a3_0x1f8b('0x41')])?(0x0,metric_logger_1[a3_0x1f8b('0x10')])(_0x368e7a[a3_0x1f8b('0x1f')][a3_0x1f8b('0x41')]):metric_logger_1[a3_0x1f8b('0x30')]);const _0x421d91=(_0x1f662d=_0x368e7a[a3_0x1f8b('0x1f')])!==null&&_0x1f662d!==void 0x0?_0x1f662d:_0x368e7a;this[a3_0x1f8b('0x1c')]['apiError']=this[a3_0x1f8b('0x1c')][a3_0x1f8b('0x3c')](_0x421d91,a3_0x1f8b('0x2a'));return![];}});}['nxCloudVersion'](){try{const _0x50be7c=JSON[a3_0x1f8b('0x43')]((0x0,fs_1['readFileSync'])(a3_0x1f8b('0x3d'))[a3_0x1f8b('0x40')]());return _0x50be7c[a3_0x1f8b('0x14')]['@nrwl/nx-cloud'];}catch(_0x2229fa){return a3_0x1f8b('0x15');}}}exports[a3_0x1f8b('0x5')]=CloudRunApi;
|
|
@@ -1,79 +1 @@
|
|
|
1
|
-
|
|
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.DistributedAgentApi = 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 } = require('../../../utilities/nx-imports');
|
|
17
|
-
class DistributedAgentApi {
|
|
18
|
-
constructor(options, runGroup, agentName) {
|
|
19
|
-
this.runGroup = runGroup;
|
|
20
|
-
this.agentName = agentName;
|
|
21
|
-
this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options);
|
|
22
|
-
}
|
|
23
|
-
tasks(executionId, statusCode, completedTasks) {
|
|
24
|
-
var _a;
|
|
25
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const recorder = (0, metric_logger_1.createMetricRecorder)('dtePollTasks');
|
|
27
|
-
try {
|
|
28
|
-
const res = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/tasks', {
|
|
29
|
-
runGroup: this.runGroup,
|
|
30
|
-
agentName: this.agentName,
|
|
31
|
-
executionId,
|
|
32
|
-
statusCode,
|
|
33
|
-
completedTasks,
|
|
34
|
-
}));
|
|
35
|
-
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(res));
|
|
36
|
-
return res.data;
|
|
37
|
-
}
|
|
38
|
-
catch (e) {
|
|
39
|
-
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
40
|
-
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
|
|
41
|
-
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
42
|
-
throw e;
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
completeRunGroupWithError(error) {
|
|
47
|
-
var _a;
|
|
48
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
if (environment_1.VERBOSE_LOGGING) {
|
|
50
|
-
output.note({
|
|
51
|
-
title: 'Completing run group with an error',
|
|
52
|
-
bodyLines: [`runGroup: ${this.runGroup}`, `error: ${error}`],
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
const recorder = (0, metric_logger_1.createMetricRecorder)('completeRunGroup');
|
|
56
|
-
try {
|
|
57
|
-
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/complete-run-group', {
|
|
58
|
-
runGroup: this.runGroup,
|
|
59
|
-
agentName: this.agentName,
|
|
60
|
-
criticalErrorMessage: error,
|
|
61
|
-
}));
|
|
62
|
-
if (environment_1.VERBOSE_LOGGING) {
|
|
63
|
-
output.note({
|
|
64
|
-
title: 'Completed run group with an error',
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
|
|
68
|
-
}
|
|
69
|
-
catch (e) {
|
|
70
|
-
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
71
|
-
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
|
|
72
|
-
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
73
|
-
console.error(e);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.DistributedAgentApi = DistributedAgentApi;
|
|
79
|
-
//# sourceMappingURL=distributed-agent.api.js.map
|
|
1
|
+
const a4_0x5065=['apply','dtePollTasks','mapRespToPerfEntry','completeRunGroup','data','defineProperty','value','apiAxiosInstance','runGroup:\x20','axiosException','/nx-cloud/executions/tasks','next','../../../utilities/axios','error:\x20','response','../../../utilities/environment','__esModule','RUNNER_FAILURE_PERF_ENTRY','Completing\x20run\x20group\x20with\x20an\x20error','DistributedAgentApi','done','note','axiosMultipleTries','recordMetric','createApiAxiosInstance','VERBOSE_LOGGING','agentName','error','__awaiter','post','../../../utilities/nx-imports','runGroup','createMetricRecorder','then'];(function(_0x49bb44,_0x5065d7){const _0x2f9b04=function(_0x1c779a){while(--_0x1c779a){_0x49bb44['push'](_0x49bb44['shift']());}};_0x2f9b04(++_0x5065d7);}(a4_0x5065,0x19a));const a4_0x2f9b=function(_0x49bb44,_0x5065d7){_0x49bb44=_0x49bb44-0x0;let _0x2f9b04=a4_0x5065[_0x49bb44];return _0x2f9b04;};'use strict';var __awaiter=this&&this[a4_0x2f9b('0x1a')]||function(_0x458a67,_0x24d881,_0x143803,_0x38056d){function _0x3c4e1f(_0x2d6390){return _0x2d6390 instanceof _0x143803?_0x2d6390:new _0x143803(function(_0x5bc09d){_0x5bc09d(_0x2d6390);});}return new(_0x143803||(_0x143803=Promise))(function(_0x4529df,_0x366897){function _0x106c2f(_0x5cba01){try{_0x1021f2(_0x38056d['next'](_0x5cba01));}catch(_0x3fb002){_0x366897(_0x3fb002);}}function _0x1dc149(_0x16ad8a){try{_0x1021f2(_0x38056d['throw'](_0x16ad8a));}catch(_0x371e26){_0x366897(_0x371e26);}}function _0x1021f2(_0x72cae8){_0x72cae8[a4_0x2f9b('0x12')]?_0x4529df(_0x72cae8[a4_0x2f9b('0x4')]):_0x3c4e1f(_0x72cae8['value'])[a4_0x2f9b('0x1f')](_0x106c2f,_0x1dc149);}_0x1021f2((_0x38056d=_0x38056d[a4_0x2f9b('0x20')](_0x458a67,_0x24d881||[]))[a4_0x2f9b('0x9')]());});};Object[a4_0x2f9b('0x3')](exports,a4_0x2f9b('0xe'),{'value':!![]});exports[a4_0x2f9b('0x11')]=void 0x0;const axios_1=require(a4_0x2f9b('0xa'));const environment_1=require(a4_0x2f9b('0xd'));const metric_logger_1=require('../../../utilities/metric-logger');const {output}=require(a4_0x2f9b('0x1c'));class DistributedAgentApi{constructor(_0xa4c314,_0x4ef91b,_0x404acb){this[a4_0x2f9b('0x1d')]=_0x4ef91b;this[a4_0x2f9b('0x18')]=_0x404acb;this[a4_0x2f9b('0x5')]=(0x0,axios_1[a4_0x2f9b('0x16')])(_0xa4c314);}['tasks'](_0x3aa454,_0x214e88,_0x1a2062){var _0x561284;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x5039b3=(0x0,metric_logger_1[a4_0x2f9b('0x1e')])(a4_0x2f9b('0x21'));try{const _0x3e09a8=yield(0x0,axios_1[a4_0x2f9b('0x14')])(()=>this['apiAxiosInstance'][a4_0x2f9b('0x1b')](a4_0x2f9b('0x8'),{'runGroup':this[a4_0x2f9b('0x1d')],'agentName':this[a4_0x2f9b('0x18')],'executionId':_0x3aa454,'statusCode':_0x214e88,'completedTasks':_0x1a2062}));_0x5039b3[a4_0x2f9b('0x15')]((0x0,metric_logger_1[a4_0x2f9b('0x0')])(_0x3e09a8));return _0x3e09a8[a4_0x2f9b('0x2')];}catch(_0x2f6c28){_0x5039b3[a4_0x2f9b('0x15')](((_0x561284=_0x2f6c28===null||_0x2f6c28===void 0x0?void 0x0:_0x2f6c28['axiosException'])===null||_0x561284===void 0x0?void 0x0:_0x561284[a4_0x2f9b('0xc')])?(0x0,metric_logger_1['mapRespToPerfEntry'])(_0x2f6c28['axiosException'][a4_0x2f9b('0xc')]):metric_logger_1[a4_0x2f9b('0xf')]);throw _0x2f6c28;}});}['completeRunGroupWithError'](_0x31d928){var _0x4919f2;return __awaiter(this,void 0x0,void 0x0,function*(){if(environment_1[a4_0x2f9b('0x17')]){output[a4_0x2f9b('0x13')]({'title':a4_0x2f9b('0x10'),'bodyLines':[a4_0x2f9b('0x6')+this[a4_0x2f9b('0x1d')],a4_0x2f9b('0xb')+_0x31d928]});}const _0x124ee6=(0x0,metric_logger_1[a4_0x2f9b('0x1e')])(a4_0x2f9b('0x1'));try{const _0x126c8e=yield(0x0,axios_1[a4_0x2f9b('0x14')])(()=>this[a4_0x2f9b('0x5')][a4_0x2f9b('0x1b')]('/nx-cloud/executions/complete-run-group',{'runGroup':this[a4_0x2f9b('0x1d')],'agentName':this[a4_0x2f9b('0x18')],'criticalErrorMessage':_0x31d928}));if(environment_1[a4_0x2f9b('0x17')]){output['note']({'title':'Completed\x20run\x20group\x20with\x20an\x20error'});}_0x124ee6['recordMetric']((0x0,metric_logger_1[a4_0x2f9b('0x0')])(_0x126c8e));}catch(_0xad942){_0x124ee6[a4_0x2f9b('0x15')](((_0x4919f2=_0xad942===null||_0xad942===void 0x0?void 0x0:_0xad942[a4_0x2f9b('0x7')])===null||_0x4919f2===void 0x0?void 0x0:_0x4919f2[a4_0x2f9b('0xc')])?(0x0,metric_logger_1['mapRespToPerfEntry'])(_0xad942[a4_0x2f9b('0x7')][a4_0x2f9b('0xc')]):metric_logger_1[a4_0x2f9b('0xf')]);console[a4_0x2f9b('0x19')](_0xad942);}});}}exports[a4_0x2f9b('0x11')]=DistributedAgentApi;
|
|
@@ -1,240 +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) {
|
|
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
|
+
const a5_0x3321=['projects','Duplicate\x20Agent\x20ID\x20Detected','error','throw','exit','NX_AGENT_NAME','__awaiter','Agent\x20','This\x20can\x20also\x20be\x20a\x20false\x20positive\x20caused\x20by\x20agents\x20that\x20did\x20not\x20shut\x20down\x20correctly.','unlinkSync','random','child_process','mkdirSync','options','defineProperty','Critical\x20Error\x20in\x20Agent:\x20\x22','Waiting...','taskId','params','target','toString','Fetching\x20tasks...','inherit','SIGINT','End\x20all\x20currently\x20running\x20agents,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22,\x20and\x20try\x20again.','completed:\x20','./distributed-agent.api','../../../utilities/create-no-new-messages-timeout','Distributed\x20Execution\x20Terminated','push','tasks','../../../utilities/metric-logger','getTime','cacheDirectory','configuration','/tasks-hashes-','submitRunMetrics','getRunGroup','execSync','maxParallel','retryDuring','number\x20of\x20tasks:\x20','writeFileSync','next','warn','map','true','DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE','CIRCLE_STAGE','We\x20have\x20detected\x20other\x20agents\x20running\x20in\x20this\x20workspace.\x20This\x20can\x20cause\x20unexpected\x20behavior.','note','If\x20you\x20believe\x20this\x20is\x20the\x20case,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22.','parse','projectName','../../../utilities/waiter','env','done','createNoNewMessagesTimeout','wait','completedTasks','/nx.json','join','startAgent','./node_modules/.cache/nx',').\x20Tasks\x20hashes\x20haven\x27t\x20been\x20recorded.','Other\x20Nx\x20Cloud\x20Agents\x20Detected','../../error/print-run-group-error','Command\x20execution\x20failed\x20(distributed\x20task\x20execution:\x20','includes','VERBOSE_LOGGING','Waiter','reset','floor','\x20--projects=','completedStatusCode','executionId','catch','.lock','../../../utilities/environment','Error:','status','completeRunGroupWithError','/lockfiles','apply','readFileSync','assign','We\x20have\x20detected\x20another\x20agent\x20with\x20this\x20ID\x20running\x20in\x20this\x20workspace.\x20This\x20should\x20not\x20happen.','completed','__esModule','length','error:\x20','API\x20Response','tasksRunnerOptions','printRunGroupError','\x20--parallel\x20--max-parallel=','then','Starting\x20an\x20agent\x20for\x20running\x20Nx\x20tasks','maxParallel:\x20','criticalErrorMessage'];(function(_0x10aeaa,_0x332118){const _0x473677=function(_0x349e15){while(--_0x349e15){_0x10aeaa['push'](_0x10aeaa['shift']());}};_0x473677(++_0x332118);}(a5_0x3321,0xaa));const a5_0x4736=function(_0x10aeaa,_0x332118){_0x10aeaa=_0x10aeaa-0x0;let _0x473677=a5_0x3321[_0x10aeaa];return _0x473677;};'use strict';var __awaiter=this&&this[a5_0x4736('0x22')]||function(_0x2c9164,_0x5771e6,_0xf996d4,_0x1fba06){function _0x3aa26b(_0x16139b){return _0x16139b instanceof _0xf996d4?_0x16139b:new _0xf996d4(function(_0x2dcd6b){_0x2dcd6b(_0x16139b);});}return new(_0xf996d4||(_0xf996d4=Promise))(function(_0x3fc637,_0x4c5d2c){function _0x21c530(_0x11be16){try{_0x82d0a2(_0x1fba06[a5_0x4736('0x47')](_0x11be16));}catch(_0x51f888){_0x4c5d2c(_0x51f888);}}function _0x41813b(_0x4ac455){try{_0x82d0a2(_0x1fba06[a5_0x4736('0x1f')](_0x4ac455));}catch(_0x388775){_0x4c5d2c(_0x388775);}}function _0x82d0a2(_0x1e7348){_0x1e7348[a5_0x4736('0x54')]?_0x3fc637(_0x1e7348['value']):_0x3aa26b(_0x1e7348['value'])[a5_0x4736('0x18')](_0x21c530,_0x41813b);}_0x82d0a2((_0x1fba06=_0x1fba06[a5_0x4736('0xc')](_0x2c9164,_0x5771e6||[]))[a5_0x4736('0x47')]());});};Object[a5_0x4736('0x2a')](exports,a5_0x4736('0x11'),{'value':!![]});exports['startAgent']=void 0x0;const child_process_1=require(a5_0x4736('0x27'));const stripJsonComments=require('strip-json-comments');const distributed_agent_api_1=require(a5_0x4736('0x36'));const waiter_1=require(a5_0x4736('0x52'));const environment_1=require(a5_0x4736('0x7'));const print_run_group_error_1=require(a5_0x4736('0x5e'));const create_no_new_messages_timeout_1=require(a5_0x4736('0x37'));const fs_1=require('fs');const metric_logger_1=require(a5_0x4736('0x3b'));const {output,workspaceRoot}=require('../../../utilities/nx-imports');function executeTasks(_0x44f08b,_0x92c848){return __awaiter(this,void 0x0,void 0x0,function*(){let _0x47273e=0x0;let _0x50302a=null;const _0x15c844=(0x0,create_no_new_messages_timeout_1[a5_0x4736('0x55')])();const _0x211d1b=new waiter_1[(a5_0x4736('0x62'))]();let _0x478c38=[];const _0x423732=new Date();let _0xca392f=![];while(!![]){if(environment_1[a5_0x4736('0x61')]){output[a5_0x4736('0x4e')]({'title':a5_0x4736('0x31')});}_0x50302a=yield _0x92c848[a5_0x4736('0x3a')](_0x50302a?_0x50302a['executionId']:null,_0x47273e,_0x478c38);if(environment_1['VERBOSE_LOGGING']){output[a5_0x4736('0x4e')]({'title':a5_0x4736('0x14'),'bodyLines':[a5_0x4736('0x35')+_0x50302a[a5_0x4736('0x10')],'retryDuring:\x20'+_0x50302a[a5_0x4736('0x44')],'executionId:\x20'+_0x50302a[a5_0x4736('0x4')],a5_0x4736('0x45')+_0x50302a[a5_0x4736('0x3a')][a5_0x4736('0x12')],a5_0x4736('0x13')+_0x50302a[a5_0x4736('0x1b')],a5_0x4736('0x1a')+_0x50302a[a5_0x4736('0x43')]]});}if(_0x50302a[a5_0x4736('0x1b')]){output[a5_0x4736('0x1e')]({'title':a5_0x4736('0x38'),'bodyLines':[a5_0x4736('0x8'),_0x50302a[a5_0x4736('0x1b')]]});process[a5_0x4736('0x20')](0x0);}if((_0x50302a===null||_0x50302a===void 0x0?void 0x0:_0x50302a[a5_0x4736('0x44')])&&(_0x50302a===null||_0x50302a===void 0x0?void 0x0:_0x50302a[a5_0x4736('0x44')])!==0x0&&!_0xca392f&&new Date()[a5_0x4736('0x3c')]()-_0x423732[a5_0x4736('0x3c')]()>_0x50302a[a5_0x4736('0x44')]){yield _0x211d1b[a5_0x4736('0x56')]();continue;}if(_0x50302a[a5_0x4736('0x10')])return;_0x15c844(_0x50302a[a5_0x4736('0x3a')][a5_0x4736('0x49')](_0x2a16e9=>_0x2a16e9[a5_0x4736('0x2d')])['join'](''));if(!_0x50302a[a5_0x4736('0x4')]){if(environment_1[a5_0x4736('0x61')]){output[a5_0x4736('0x4e')]({'title':a5_0x4736('0x2c')});}yield _0x211d1b[a5_0x4736('0x56')]();_0x47273e=0x0;_0x478c38=[];continue;}_0x211d1b[a5_0x4736('0x0')]();_0xca392f=!![];const _0xa7753c=invokeTasksUsingRunMany(_0x44f08b,_0x50302a[a5_0x4736('0x4')],_0x50302a['tasks'],_0x50302a[a5_0x4736('0x43')]);_0x47273e=_0xa7753c[a5_0x4736('0x3')];_0x478c38=_0xa7753c[a5_0x4736('0x57')];}});}function readCompletedTasks(_0x36b040,_0x301758){const _0x299163=a5_0x4736('0x5f')+_0x301758+a5_0x4736('0x5c');let _0x1a437;try{const _0x21fbce=_0x36b040[a5_0x4736('0x3d')]||a5_0x4736('0x5b');const _0x1e8697=_0x21fbce+a5_0x4736('0x3f')+_0x301758;_0x1a437=JSON['parse']((0x0,fs_1[a5_0x4736('0xd')])(_0x1e8697)[a5_0x4736('0x30')]());(0x0,fs_1[a5_0x4736('0x25')])(_0x1e8697);}catch(_0x585e83){throw new Error(_0x299163);}if(_0x1a437[a5_0x4736('0x12')]==0x0){throw new Error(_0x299163);}return _0x1a437;}function invokeTasksUsingRunMany(_0x4c3fa7,_0x1b10b2,_0xea45d2,_0x1d35d0){let _0x280016=0x0;const _0x1ed76f=[];for(const _0x1ae264 of groupByTarget(_0xea45d2)){const _0xa3b769=_0x1ae264[a5_0x4736('0x3e')]?'--configuration='+_0x1ae264[a5_0x4736('0x3e')]:'';const _0x43624d=_0x1d35d0>0x1?a5_0x4736('0x17')+_0x1d35d0:'';const _0x2cac62='npx\x20nx\x20run-many\x20--target='+_0x1ae264[a5_0x4736('0x2f')]+'\x20'+_0xa3b769+a5_0x4736('0x2')+_0x1ae264[a5_0x4736('0x1c')][a5_0x4736('0x59')](',')+'\x20'+_0x1ae264[a5_0x4736('0x2e')]+_0x43624d;if(environment_1[a5_0x4736('0x61')]){output[a5_0x4736('0x4e')]({'title':'Executing:\x20\x27'+_0x2cac62+'\x27'});}try{(0x0,child_process_1[a5_0x4736('0x42')])(_0x2cac62,{'stdio':[a5_0x4736('0x32'),a5_0x4736('0x32'),'inherit'],'env':Object[a5_0x4736('0xe')](Object[a5_0x4736('0xe')]({},process[a5_0x4736('0x53')]),{'NX_CACHE_FAILURES':a5_0x4736('0x4a'),'NX_CLOUD_DISTRIBUTED_EXECUTION_ID':_0x1b10b2})});}catch(_0x120998){if(_0x120998[a5_0x4736('0x9')]===environment_1[a5_0x4736('0x4b')]){throw _0x120998;}else{_0x280016=0x1;}}finally{_0x1ed76f[a5_0x4736('0x39')](...readCompletedTasks(_0x4c3fa7,_0x1b10b2));}}return{'completedStatusCode':_0x280016,'completedTasks':_0x1ed76f};}function groupByTarget(_0x3849b3){const _0x210249=[];_0x3849b3['forEach'](_0x58b9fb=>{const _0x297e6a=_0x210249['find'](_0x3a9cf0=>_0x3a9cf0[a5_0x4736('0x2f')]===_0x58b9fb[a5_0x4736('0x2f')]&&_0x3a9cf0[a5_0x4736('0x3e')]===_0x58b9fb['configuration']);if(_0x297e6a){_0x297e6a[a5_0x4736('0x1c')]['push'](_0x58b9fb[a5_0x4736('0x51')]);}else{_0x210249[a5_0x4736('0x39')]({'target':_0x58b9fb[a5_0x4736('0x2f')],'projects':[_0x58b9fb['projectName']],'params':_0x58b9fb['params'],'configuration':_0x58b9fb[a5_0x4736('0x3e')]});}});return _0x210249;}function getAgentName(){if(process[a5_0x4736('0x53')][a5_0x4736('0x21')]!==undefined){return process['env'][a5_0x4736('0x21')];}else if(process[a5_0x4736('0x53')]['CIRCLECI']!==undefined){return process[a5_0x4736('0x53')][a5_0x4736('0x4c')];}else{return a5_0x4736('0x23')+Math[a5_0x4736('0x1')](Math[a5_0x4736('0x26')]()*0x186a0);}}function createAgentLockfile(_0x1dc43a,_0x12948){const _0x2d52fa=_0x1dc43a['cacheDirectory']||a5_0x4736('0x5b');const _0x37922c=_0x2d52fa+a5_0x4736('0xb');const _0x2f9dc4=_0x37922c+'/'+_0x12948+a5_0x4736('0x6');if(!(0x0,fs_1['existsSync'])(_0x37922c)){(0x0,fs_1[a5_0x4736('0x28')])(_0x37922c,{'recursive':!![]});}const _0x44ce80=(0x0,fs_1['readdirSync'])(_0x37922c);if(_0x44ce80[a5_0x4736('0x12')]){if(_0x44ce80[a5_0x4736('0x60')](_0x12948+a5_0x4736('0x6'))){output[a5_0x4736('0x1e')]({'title':a5_0x4736('0x1d'),'bodyLines':[a5_0x4736('0xf'),'',a5_0x4736('0x34')]});process[a5_0x4736('0x20')](0x1);}output[a5_0x4736('0x48')]({'title':a5_0x4736('0x5d'),'bodyLines':[a5_0x4736('0x4d'),'',a5_0x4736('0x24'),a5_0x4736('0x4f')]});}(0x0,fs_1[a5_0x4736('0x46')])(_0x2f9dc4,'');process['on'](a5_0x4736('0x20'),_0x3599ff=>cleanupAgentLockfile(_0x2f9dc4,_0x3599ff));process['on'](a5_0x4736('0x33'),()=>cleanupAgentLockfile(_0x2f9dc4,0x0));}function cleanupAgentLockfile(_0x140e74,_0x3b0804){if((0x0,fs_1['existsSync'])(_0x140e74)){(0x0,fs_1[a5_0x4736('0x25')])(_0x140e74);process[a5_0x4736('0x20')](_0x3b0804);}}function startAgent(){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x14775f=(0x0,environment_1[a5_0x4736('0x41')])();if(!_0x14775f){(0x0,print_run_group_error_1[a5_0x4736('0x16')])();return process[a5_0x4736('0x20')](0x1);}output[a5_0x4736('0x4e')]({'title':a5_0x4736('0x19')});const _0x5f239e=JSON[a5_0x4736('0x50')](stripJsonComments((0x0,fs_1[a5_0x4736('0xd')])(workspaceRoot+a5_0x4736('0x58'))[a5_0x4736('0x30')]()))[a5_0x4736('0x15')]['default'][a5_0x4736('0x29')];const _0x5dd8f7=getAgentName();createAgentLockfile(_0x5f239e,_0x5dd8f7);const _0x27f018=new distributed_agent_api_1['DistributedAgentApi'](_0x5f239e,_0x14775f,_0x5dd8f7);return executeTasks(_0x5f239e,_0x27f018)[a5_0x4736('0x18')](_0x464113=>__awaiter(this,void 0x0,void 0x0,function*(){yield(0x0,metric_logger_1[a5_0x4736('0x40')])(_0x5f239e);return _0x464113;}))[a5_0x4736('0x5')](_0x1137ea=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x27f018[a5_0x4736('0xa')](a5_0x4736('0x2b')+_0x1137ea['message']+'\x22');throw _0x1137ea;}));});}exports[a5_0x4736('0x5a')]=startAgent;
|