@nrwl/nx-cloud 15.2.0-beta.6 → 15.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,133 +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.CloudRemoteCache = void 0;
13
- const environment_1 = require("../../../utilities/environment");
14
- const { output } = require('../../../utilities/nx-imports');
15
- class CloudRemoteCache {
16
- constructor(messages, api, runContext, fileStorage, distributedExecutionId, storeInCurrentProcess) {
17
- this.messages = messages;
18
- this.api = api;
19
- this.runContext = runContext;
20
- this.fileStorage = fileStorage;
21
- this.distributedExecutionId = distributedExecutionId;
22
- this.storeInCurrentProcess = storeInCurrentProcess;
23
- this.storeRequests = [];
24
- this.delayedStoreRequests = [];
25
- }
26
- retrieve(hash, cacheDirectory) {
27
- var _a;
28
- return __awaiter(this, void 0, void 0, function* () {
29
- if (this.messages.cacheError)
30
- return false;
31
- const hashUrls = yield this.hashUrls(hash);
32
- if (!hashUrls || !hashUrls.get) {
33
- if (environment_1.VERBOSE_LOGGING) {
34
- output.note({ title: `Nx Cloud: Cache miss ${hash}.` });
35
- }
36
- this.runContext.statuses[hash] = 'cache-miss';
37
- return false;
38
- }
39
- try {
40
- yield this.fileStorage.retrieve(hash, hashUrls.get, cacheDirectory);
41
- this.runContext.statuses[hash] = 'remote-cache-hit';
42
- return true;
43
- }
44
- catch (ee) {
45
- const e = (_a = ee.axiosException) !== null && _a !== void 0 ? _a : ee;
46
- // TODO: vsavkin remove this handling Oct 2023
47
- // 404 indicates that something is broken, but older versions
48
- // of the api can result in such errors
49
- // we ignore them for now
50
- if (e.response && e.response.status === 404) {
51
- if (environment_1.VERBOSE_LOGGING) {
52
- output.note({ title: `Nx Cloud: Cache miss ${hash}. Status 404.` });
53
- }
54
- // cache miss. print nothing
55
- }
56
- else {
57
- this.messages.cacheError = this.messages.extractErrorMessage(e, 'storage');
58
- }
59
- this.runContext.statuses[hash] = 'cache-miss';
60
- return false;
61
- }
62
- });
63
- }
64
- store(hash, cacheDirectory) {
65
- return __awaiter(this, void 0, void 0, function* () {
66
- if (this.messages.cacheError)
67
- return false;
68
- const res = Promise.resolve().then(() => __awaiter(this, void 0, void 0, function* () {
69
- var _a;
70
- const hashUrls = yield this.hashUrls(hash);
71
- if (!hashUrls)
72
- return false;
73
- if (!hashUrls.put) {
74
- if (environment_1.VERBOSE_LOGGING) {
75
- output.note({
76
- title: `Nx Cloud: Skipping storing ${hash}.`,
77
- bodyLines: [
78
- `There are several reasons why this can happen.`,
79
- `Maybe you are using a read-only token or the artifact has already being uploaded.`,
80
- ],
81
- });
82
- }
83
- return true;
84
- }
85
- if (!this.storeInCurrentProcess) {
86
- this.delayedStoreRequests.push({ hash: hash, url: hashUrls.put });
87
- return true;
88
- }
89
- try {
90
- yield this.fileStorage.store(hash, hashUrls.put, cacheDirectory);
91
- return true;
92
- }
93
- catch (ee) {
94
- const e = (_a = ee.axiosException) !== null && _a !== void 0 ? _a : ee;
95
- this.messages.cacheError = this.messages.extractErrorMessage(e, 'storage');
96
- return false;
97
- }
98
- }));
99
- this.storeRequests.push(res);
100
- return res;
101
- });
102
- }
103
- hashUrls(hash) {
104
- return __awaiter(this, void 0, void 0, function* () {
105
- if (hash in this.runContext.requests) {
106
- return (yield this.runContext.requests[hash])[hash];
107
- }
108
- else {
109
- const scheduledTaskHashesWithoutRequests = this.runContext.scheduledTasks
110
- .filter((t) => !this.runContext.requests[t.hash])
111
- .map((t) => t.hash);
112
- if (scheduledTaskHashesWithoutRequests.indexOf(hash) === -1) {
113
- scheduledTaskHashesWithoutRequests.push(hash);
114
- }
115
- const request = this.api.startRun(this.distributedExecutionId, scheduledTaskHashesWithoutRequests);
116
- scheduledTaskHashesWithoutRequests.forEach((taskHash) => {
117
- this.runContext.requests[taskHash] = request;
118
- });
119
- return (yield request)[hash];
120
- }
121
- });
122
- }
123
- waitForStoreRequestsToComplete() {
124
- return __awaiter(this, void 0, void 0, function* () {
125
- const res = yield Promise.all(this.storeRequests).then((r) => r.reduce((a, b) => a && b, true));
126
- if (!res) {
127
- throw new Error(`Error when storing artifacts`);
128
- }
129
- });
130
- }
131
- }
132
- exports.CloudRemoteCache = CloudRemoteCache;
133
- //# sourceMappingURL=cloud-remote-cache.js.map
1
+ const a2_0x46f5=['retrieve','then','requests','CloudRemoteCache','status','fileStorage','throw','api','There\x20are\x20several\x20reasons\x20why\x20this\x20can\x20happen.','hashUrls','done','value','storeInCurrentProcess','note','get','.\x20Status\x20404.','storage','axiosException','__awaiter','VERBOSE_LOGGING','put','forEach','distributedExecutionId','scheduledTasks','hash','defineProperty','../../../utilities/nx-imports','Error\x20when\x20storing\x20artifacts','statuses','runContext','startRun','indexOf','map','response','next','store','../../../utilities/environment','cache-miss','waitForStoreRequestsToComplete','Nx\x20Cloud:\x20Skipping\x20storing\x20','cacheError','reduce','all','delayedStoreRequests','apply','filter','storeRequests','push','Nx\x20Cloud:\x20Cache\x20miss\x20','extractErrorMessage','__esModule','messages'];(function(_0x58baed,_0x46f531){const _0x5997e6=function(_0x1ba20d){while(--_0x1ba20d){_0x58baed['push'](_0x58baed['shift']());}};_0x5997e6(++_0x46f531);}(a2_0x46f5,0x1d9));const a2_0x5997=function(_0x58baed,_0x46f531){_0x58baed=_0x58baed-0x0;let _0x5997e6=a2_0x46f5[_0x58baed];return _0x5997e6;};'use strict';var __awaiter=this&&this[a2_0x5997('0xd')]||function(_0x3f71b2,_0x4865a7,_0x43bf2a,_0x17a3c4){function _0x1fea28(_0x3e9481){return _0x3e9481 instanceof _0x43bf2a?_0x3e9481:new _0x43bf2a(function(_0x4f9156){_0x4f9156(_0x3e9481);});}return new(_0x43bf2a||(_0x43bf2a=Promise))(function(_0x36ab43,_0xb3d2ac){function _0x2eaffc(_0x1cb0ae){try{_0x4ca87f(_0x17a3c4[a2_0x5997('0x1d')](_0x1cb0ae));}catch(_0x1f42ca){_0xb3d2ac(_0x1f42ca);}}function _0x2e04cc(_0x35eaa8){try{_0x4ca87f(_0x17a3c4[a2_0x5997('0x1')](_0x35eaa8));}catch(_0x200a62){_0xb3d2ac(_0x200a62);}}function _0x4ca87f(_0x50ef1e){_0x50ef1e[a2_0x5997('0x5')]?_0x36ab43(_0x50ef1e[a2_0x5997('0x6')]):_0x1fea28(_0x50ef1e[a2_0x5997('0x6')])[a2_0x5997('0x30')](_0x2eaffc,_0x2e04cc);}_0x4ca87f((_0x17a3c4=_0x17a3c4[a2_0x5997('0x27')](_0x3f71b2,_0x4865a7||[]))[a2_0x5997('0x1d')]());});};Object[a2_0x5997('0x14')](exports,a2_0x5997('0x2d'),{'value':!![]});exports[a2_0x5997('0x32')]=void 0x0;const environment_1=require(a2_0x5997('0x1f'));const {output}=require(a2_0x5997('0x15'));class CloudRemoteCache{constructor(_0x317846,_0x436edc,_0x3e3ac2,_0x404204,_0x5b62e6,_0x26aacb){this[a2_0x5997('0x2e')]=_0x317846;this[a2_0x5997('0x2')]=_0x436edc;this[a2_0x5997('0x18')]=_0x3e3ac2;this['fileStorage']=_0x404204;this[a2_0x5997('0x11')]=_0x5b62e6;this[a2_0x5997('0x7')]=_0x26aacb;this[a2_0x5997('0x29')]=[];this['delayedStoreRequests']=[];}['retrieve'](_0x535c2e,_0x368f8d){var _0x40cefb;return __awaiter(this,void 0x0,void 0x0,function*(){if(this[a2_0x5997('0x2e')][a2_0x5997('0x23')])return![];const _0x39c4a5=yield this[a2_0x5997('0x4')](_0x535c2e);if(!_0x39c4a5||!_0x39c4a5[a2_0x5997('0x9')]){if(environment_1[a2_0x5997('0xe')]){output[a2_0x5997('0x8')]({'title':a2_0x5997('0x2b')+_0x535c2e+'.'});}this['runContext']['statuses'][_0x535c2e]=a2_0x5997('0x20');return![];}try{yield this[a2_0x5997('0x0')][a2_0x5997('0x2f')](_0x535c2e,_0x39c4a5[a2_0x5997('0x9')],_0x368f8d);this[a2_0x5997('0x18')][a2_0x5997('0x17')][_0x535c2e]='remote-cache-hit';return!![];}catch(_0x3d5dd7){const _0x84df28=(_0x40cefb=_0x3d5dd7[a2_0x5997('0xc')])!==null&&_0x40cefb!==void 0x0?_0x40cefb:_0x3d5dd7;if(_0x84df28[a2_0x5997('0x1c')]&&_0x84df28[a2_0x5997('0x1c')][a2_0x5997('0x33')]===0x194){if(environment_1[a2_0x5997('0xe')]){output[a2_0x5997('0x8')]({'title':a2_0x5997('0x2b')+_0x535c2e+a2_0x5997('0xa')});}}else{this[a2_0x5997('0x2e')][a2_0x5997('0x23')]=this[a2_0x5997('0x2e')]['extractErrorMessage'](_0x84df28,a2_0x5997('0xb'));}this[a2_0x5997('0x18')]['statuses'][_0x535c2e]=a2_0x5997('0x20');return![];}});}['store'](_0x829b64,_0x545ee1){return __awaiter(this,void 0x0,void 0x0,function*(){if(this[a2_0x5997('0x2e')][a2_0x5997('0x23')])return![];const _0x2dbb55=Promise['resolve']()['then'](()=>__awaiter(this,void 0x0,void 0x0,function*(){var _0x1b82be;const _0x47a390=yield this[a2_0x5997('0x4')](_0x829b64);if(!_0x47a390)return![];if(!_0x47a390['put']){if(environment_1[a2_0x5997('0xe')]){output[a2_0x5997('0x8')]({'title':a2_0x5997('0x22')+_0x829b64+'.','bodyLines':[a2_0x5997('0x3'),'Maybe\x20you\x20are\x20using\x20a\x20read-only\x20token\x20or\x20the\x20artifact\x20has\x20already\x20being\x20uploaded.']});}return!![];}if(!this[a2_0x5997('0x7')]){this[a2_0x5997('0x26')][a2_0x5997('0x2a')]({'hash':_0x829b64,'url':_0x47a390[a2_0x5997('0xf')]});return!![];}try{yield this['fileStorage'][a2_0x5997('0x1e')](_0x829b64,_0x47a390[a2_0x5997('0xf')],_0x545ee1);return!![];}catch(_0xdbab2f){const _0xe7870=(_0x1b82be=_0xdbab2f['axiosException'])!==null&&_0x1b82be!==void 0x0?_0x1b82be:_0xdbab2f;this[a2_0x5997('0x2e')][a2_0x5997('0x23')]=this['messages'][a2_0x5997('0x2c')](_0xe7870,a2_0x5997('0xb'));return![];}}));this['storeRequests'][a2_0x5997('0x2a')](_0x2dbb55);return _0x2dbb55;});}[a2_0x5997('0x4')](_0xe36186){return __awaiter(this,void 0x0,void 0x0,function*(){if(_0xe36186 in this[a2_0x5997('0x18')]['requests']){return(yield this[a2_0x5997('0x18')]['requests'][_0xe36186])[_0xe36186];}else{const _0x1f28d6=this[a2_0x5997('0x18')][a2_0x5997('0x12')][a2_0x5997('0x28')](_0x561a65=>!this['runContext'][a2_0x5997('0x31')][_0x561a65[a2_0x5997('0x13')]])[a2_0x5997('0x1b')](_0x1e8597=>_0x1e8597[a2_0x5997('0x13')]);if(_0x1f28d6[a2_0x5997('0x1a')](_0xe36186)===-0x1){_0x1f28d6[a2_0x5997('0x2a')](_0xe36186);}const _0xc1d723=this['api'][a2_0x5997('0x19')](this['distributedExecutionId'],_0x1f28d6);_0x1f28d6[a2_0x5997('0x10')](_0xf7992=>{this[a2_0x5997('0x18')][a2_0x5997('0x31')][_0xf7992]=_0xc1d723;});return(yield _0xc1d723)[_0xe36186];}});}[a2_0x5997('0x21')](){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x1475ad=yield Promise[a2_0x5997('0x25')](this[a2_0x5997('0x29')])['then'](_0x15f2ec=>_0x15f2ec[a2_0x5997('0x24')]((_0x5386f0,_0x14ec8a)=>_0x5386f0&&_0x14ec8a,!![]));if(!_0x1475ad){throw new Error(a2_0x5997('0x16'));}});}}exports[a2_0x5997('0x32')]=CloudRemoteCache;
@@ -1,170 +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.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
- // API is not working, don't make the end request
31
- if (this.messages.apiError)
32
- return {};
33
- const recorder = (0, metric_logger_1.createMetricRecorder)('startRun');
34
- try {
35
- const request = {
36
- meta: {
37
- nxCloudVersion: this.nxCloudVersion(),
38
- },
39
- branch: (0, environment_1.getBranch)(),
40
- runGroup: (0, environment_1.getRunGroup)(),
41
- distributedExecutionId,
42
- hashes,
43
- };
44
- if (environment_1.VERBOSE_LOGGING) {
45
- output.note({
46
- title: 'RunStart',
47
- bodyLines: ['\n' + JSON.stringify(request, null, 2)],
48
- });
49
- }
50
- const resp = yield (0, axios_1.printDuration)('RunStart duration', () => (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/runs/start', request)));
51
- recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
52
- if (resp.data && resp.data.message) {
53
- this.messages.message = resp.data.message;
54
- }
55
- if (!resp.data || !resp.data.urls) {
56
- this.messages.apiError = `Invalid Nx Cloud response: ${JSON.stringify(resp.data)}`;
57
- return {};
58
- }
59
- return resp.data.urls;
60
- }
61
- catch (e) {
62
- recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
63
- ? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
64
- : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
65
- this.messages.apiError = this.messages.extractErrorMessage(e, 'api');
66
- return {};
67
- }
68
- });
69
- }
70
- createReqBody(run, tasks, linkId) {
71
- const uncompressedReqBody = {
72
- meta: {
73
- nxCloudVersion: this.nxCloudVersion(),
74
- },
75
- tasks,
76
- run,
77
- linkId,
78
- machineInfo: this.machineInfo,
79
- };
80
- return JSON.stringify(uncompressedReqBody);
81
- }
82
- endRun(run, tasks, linkId) {
83
- var _a, _b;
84
- return __awaiter(this, void 0, void 0, function* () {
85
- // API is not working, don't make the end request
86
- if (this.messages.apiError)
87
- return false;
88
- let uncompressedBodyString = this.createReqBody(run, tasks, linkId);
89
- // if the req body is > 20mb, remove hashDetails
90
- if (uncompressedBodyString.length > 20 * 1000 * 1000) {
91
- uncompressedBodyString = this.createReqBody(run, tasks.map((t) => (Object.assign(Object.assign({}, t), { hashDetails: undefined }))));
92
- }
93
- const uncompressedBuffer = Buffer.from(uncompressedBodyString);
94
- const compressedBuffer = yield (0, util_1.promisify)(zlib_1.gzip)(uncompressedBuffer);
95
- const recorder = (0, metric_logger_1.createMetricRecorder)('endRun');
96
- try {
97
- if (environment_1.VERBOSE_LOGGING) {
98
- const t = tasks.map((tt) => {
99
- return Object.assign(Object.assign({}, tt), { terminalOutput: tt.terminalOutput
100
- ? `${tt.terminalOutput.slice(0, 20)}...`
101
- : undefined });
102
- });
103
- output.note({
104
- title: 'RunEnd. Completed tasks',
105
- bodyLines: ['\n' + JSON.stringify(t, null, 2)],
106
- });
107
- }
108
- const resp = yield (0, axios_1.printDuration)('RunEnd duration', () => (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/runs/end', compressedBuffer, {
109
- headers: Object.assign(Object.assign({}, this.apiAxiosInstance.defaults.headers), { 'Content-Encoding': 'gzip', 'Content-Type': 'application/octet-stream' }),
110
- })));
111
- if (resp) {
112
- recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
113
- if (resp.data && resp.data.runUrl && resp.data.status === 'success') {
114
- this.runContext.runUrl = resp.data.runUrl;
115
- return true;
116
- }
117
- if (resp.data && resp.data.status) {
118
- this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data.message)}`;
119
- }
120
- else if (resp.data && typeof resp.data === 'string') {
121
- if (resp.data !== 'success') {
122
- this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data)}`;
123
- }
124
- }
125
- else {
126
- this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data)}`;
127
- }
128
- if (environment_1.VERBOSE_LOGGING) {
129
- output.note({
130
- title: 'Invalid end run response',
131
- bodyLines: [JSON.stringify(resp.data, null, 2)],
132
- });
133
- }
134
- }
135
- else {
136
- output.error({
137
- title: 'Nx Cloud: Unknown Error Occurred',
138
- bodyLines: [
139
- 'Run completion responded with `undefined`.',
140
- 'Run Details:',
141
- JSON.stringify(run, null, 2),
142
- 'Stack Trace:',
143
- JSON.stringify(new Error().stack, null, 2),
144
- ],
145
- });
146
- }
147
- return false;
148
- }
149
- catch (ee) {
150
- recorder.recordMetric(((_a = ee === null || ee === void 0 ? void 0 : ee.axiosException) === null || _a === void 0 ? void 0 : _a.response)
151
- ? (0, metric_logger_1.mapRespToPerfEntry)(ee.axiosException.response)
152
- : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
153
- const e = (_b = ee.axiosException) !== null && _b !== void 0 ? _b : ee;
154
- this.messages.apiError = this.messages.extractErrorMessage(e, 'api');
155
- return false;
156
- }
157
- });
158
- }
159
- nxCloudVersion() {
160
- try {
161
- const v = JSON.parse((0, fs_1.readFileSync)(`package.json`).toString());
162
- return v.devDependencies['@nrwl/nx-cloud'];
163
- }
164
- catch (e) {
165
- return 'unknown';
166
- }
167
- }
168
- }
169
- exports.CloudRunApi = CloudRunApi;
170
- //# sourceMappingURL=cloud-run.api.js.map
1
+ const a3_0x2247=['string','from','throw','defineProperty','apiAxiosInstance','axiosMultipleTries','@nrwl/nx-cloud','Invalid\x20end\x20run\x20response:\x20','RunStart','../../../utilities/axios','success','stack','apiError','next','parse','startRun','CloudRunApi','getRunGroup','stringify','message','extractErrorMessage','../../../utilities/metric-logger','endRun','/nx-cloud/runs/start','printDuration','application/octet-stream','defaults','value','length','assign','Invalid\x20Nx\x20Cloud\x20response:\x20','messages','runUrl','../../../utilities/environment','mapRespToPerfEntry','error','recordMetric','nxCloudVersion','Run\x20completion\x20responded\x20with\x20`undefined`.','__awaiter','machineInfo','note','headers','api','terminalOutput','Run\x20Details:','__esModule','Invalid\x20end\x20run\x20response','gzip','/nx-cloud/runs/end','toString','urls','createReqBody','apply','zlib','unknown','axiosException','map','Nx\x20Cloud:\x20Unknown\x20Error\x20Occurred','then','data','RunEnd\x20duration','post','../../../utilities/nx-imports','VERBOSE_LOGGING','runContext','createMetricRecorder','response','RunStart\x20duration'];(function(_0x327f55,_0x2247b9){const _0x1af337=function(_0xf3fab4){while(--_0xf3fab4){_0x327f55['push'](_0x327f55['shift']());}};_0x1af337(++_0x2247b9);}(a3_0x2247,0x138));const a3_0x1af3=function(_0x327f55,_0x2247b9){_0x327f55=_0x327f55-0x0;let _0x1af337=a3_0x2247[_0x327f55];return _0x1af337;};'use strict';var __awaiter=this&&this[a3_0x1af3('0x3')]||function(_0x34f598,_0x2d5a70,_0xdf71f2,_0x3c4587){function _0xd37e97(_0x26d453){return _0x26d453 instanceof _0xdf71f2?_0x26d453:new _0xdf71f2(function(_0x1d6e93){_0x1d6e93(_0x26d453);});}return new(_0xdf71f2||(_0xdf71f2=Promise))(function(_0x2a07b5,_0x101b64){function _0x53f1df(_0x520f30){try{_0x394756(_0x3c4587[a3_0x1af3('0x2e')](_0x520f30));}catch(_0x2949ba){_0x101b64(_0x2949ba);}}function _0x2a707d(_0x13274e){try{_0x394756(_0x3c4587[a3_0x1af3('0x23')](_0x13274e));}catch(_0x50920f){_0x101b64(_0x50920f);}}function _0x394756(_0x19e754){_0x19e754['done']?_0x2a07b5(_0x19e754[a3_0x1af3('0x3c')]):_0xd37e97(_0x19e754[a3_0x1af3('0x3c')])[a3_0x1af3('0x17')](_0x53f1df,_0x2a707d);}_0x394756((_0x3c4587=_0x3c4587[a3_0x1af3('0x11')](_0x34f598,_0x2d5a70||[]))[a3_0x1af3('0x2e')]());});};Object[a3_0x1af3('0x24')](exports,a3_0x1af3('0xa'),{'value':!![]});exports['CloudRunApi']=void 0x0;const axios_1=require(a3_0x1af3('0x2a'));const environment_1=require(a3_0x1af3('0x42'));const fs_1=require('fs');const zlib_1=require(a3_0x1af3('0x12'));const util_1=require('util');const metric_logger_1=require(a3_0x1af3('0x36'));const {output}=require(a3_0x1af3('0x1b'));class CloudRunApi{constructor(_0x3a9b1f,_0x5689dc,_0x45f514,_0x216607){this[a3_0x1af3('0x40')]=_0x3a9b1f;this[a3_0x1af3('0x1d')]=_0x5689dc;this[a3_0x1af3('0x4')]=_0x216607;this['apiAxiosInstance']=(0x0,axios_1['createApiAxiosInstance'])(_0x45f514);}[a3_0x1af3('0x30')](_0x25a205,_0x330f96){var _0x1be59b;return __awaiter(this,void 0x0,void 0x0,function*(){if(this[a3_0x1af3('0x40')][a3_0x1af3('0x2d')])return{};const _0x569758=(0x0,metric_logger_1['createMetricRecorder'])(a3_0x1af3('0x30'));try{const _0x20127f={'meta':{'nxCloudVersion':this[a3_0x1af3('0x1')]()},'branch':(0x0,environment_1['getBranch'])(),'runGroup':(0x0,environment_1[a3_0x1af3('0x32')])(),'distributedExecutionId':_0x25a205,'hashes':_0x330f96};if(environment_1[a3_0x1af3('0x1c')]){output[a3_0x1af3('0x5')]({'title':a3_0x1af3('0x29'),'bodyLines':['\x0a'+JSON[a3_0x1af3('0x33')](_0x20127f,null,0x2)]});}const _0x36bc00=yield(0x0,axios_1[a3_0x1af3('0x39')])(a3_0x1af3('0x20'),()=>(0x0,axios_1[a3_0x1af3('0x26')])(()=>this[a3_0x1af3('0x25')]['post'](a3_0x1af3('0x38'),_0x20127f)));_0x569758[a3_0x1af3('0x0')]((0x0,metric_logger_1[a3_0x1af3('0x43')])(_0x36bc00));if(_0x36bc00[a3_0x1af3('0x18')]&&_0x36bc00[a3_0x1af3('0x18')][a3_0x1af3('0x34')]){this[a3_0x1af3('0x40')][a3_0x1af3('0x34')]=_0x36bc00[a3_0x1af3('0x18')][a3_0x1af3('0x34')];}if(!_0x36bc00['data']||!_0x36bc00[a3_0x1af3('0x18')]['urls']){this['messages']['apiError']=a3_0x1af3('0x3f')+JSON[a3_0x1af3('0x33')](_0x36bc00['data']);return{};}return _0x36bc00[a3_0x1af3('0x18')][a3_0x1af3('0xf')];}catch(_0x546456){_0x569758[a3_0x1af3('0x0')](((_0x1be59b=_0x546456===null||_0x546456===void 0x0?void 0x0:_0x546456['axiosException'])===null||_0x1be59b===void 0x0?void 0x0:_0x1be59b['response'])?(0x0,metric_logger_1[a3_0x1af3('0x43')])(_0x546456[a3_0x1af3('0x14')]['response']):metric_logger_1['RUNNER_FAILURE_PERF_ENTRY']);this[a3_0x1af3('0x40')][a3_0x1af3('0x2d')]=this[a3_0x1af3('0x40')]['extractErrorMessage'](_0x546456,a3_0x1af3('0x7'));return{};}});}[a3_0x1af3('0x10')](_0x250f18,_0x3954d2,_0x12c6ae){const _0x3bd96d={'meta':{'nxCloudVersion':this[a3_0x1af3('0x1')]()},'tasks':_0x3954d2,'run':_0x250f18,'linkId':_0x12c6ae,'machineInfo':this[a3_0x1af3('0x4')]};return JSON[a3_0x1af3('0x33')](_0x3bd96d);}['endRun'](_0x2558e3,_0xf0c721,_0x43d8cf){var _0x1c6d17,_0x4a0617;return __awaiter(this,void 0x0,void 0x0,function*(){if(this[a3_0x1af3('0x40')]['apiError'])return![];let _0x29da6c=this[a3_0x1af3('0x10')](_0x2558e3,_0xf0c721,_0x43d8cf);if(_0x29da6c[a3_0x1af3('0x3d')]>0x14*0x3e8*0x3e8){_0x29da6c=this[a3_0x1af3('0x10')](_0x2558e3,_0xf0c721[a3_0x1af3('0x15')](_0x27243f=>Object[a3_0x1af3('0x3e')](Object[a3_0x1af3('0x3e')]({},_0x27243f),{'hashDetails':undefined})));}const _0x15110e=Buffer[a3_0x1af3('0x22')](_0x29da6c);const _0x44649f=yield(0x0,util_1['promisify'])(zlib_1[a3_0x1af3('0xc')])(_0x15110e);const _0x27387c=(0x0,metric_logger_1[a3_0x1af3('0x1e')])(a3_0x1af3('0x37'));try{if(environment_1[a3_0x1af3('0x1c')]){const _0x1a782e=_0xf0c721[a3_0x1af3('0x15')](_0x1a4f39=>{return Object[a3_0x1af3('0x3e')](Object[a3_0x1af3('0x3e')]({},_0x1a4f39),{'terminalOutput':_0x1a4f39['terminalOutput']?_0x1a4f39[a3_0x1af3('0x8')]['slice'](0x0,0x14)+'...':undefined});});output[a3_0x1af3('0x5')]({'title':'RunEnd.\x20Completed\x20tasks','bodyLines':['\x0a'+JSON['stringify'](_0x1a782e,null,0x2)]});}const _0x2861a1=yield(0x0,axios_1['printDuration'])(a3_0x1af3('0x19'),()=>(0x0,axios_1[a3_0x1af3('0x26')])(()=>this[a3_0x1af3('0x25')][a3_0x1af3('0x1a')](a3_0x1af3('0xd'),_0x44649f,{'headers':Object['assign'](Object['assign']({},this[a3_0x1af3('0x25')][a3_0x1af3('0x3b')][a3_0x1af3('0x6')]),{'Content-Encoding':a3_0x1af3('0xc'),'Content-Type':a3_0x1af3('0x3a')})})));if(_0x2861a1){_0x27387c[a3_0x1af3('0x0')]((0x0,metric_logger_1[a3_0x1af3('0x43')])(_0x2861a1));if(_0x2861a1[a3_0x1af3('0x18')]&&_0x2861a1[a3_0x1af3('0x18')][a3_0x1af3('0x41')]&&_0x2861a1['data']['status']===a3_0x1af3('0x2b')){this[a3_0x1af3('0x1d')][a3_0x1af3('0x41')]=_0x2861a1[a3_0x1af3('0x18')][a3_0x1af3('0x41')];return!![];}if(_0x2861a1[a3_0x1af3('0x18')]&&_0x2861a1[a3_0x1af3('0x18')]['status']){this[a3_0x1af3('0x40')][a3_0x1af3('0x2d')]=a3_0x1af3('0x28')+JSON[a3_0x1af3('0x33')](_0x2861a1[a3_0x1af3('0x18')][a3_0x1af3('0x34')]);}else if(_0x2861a1[a3_0x1af3('0x18')]&&typeof _0x2861a1[a3_0x1af3('0x18')]===a3_0x1af3('0x21')){if(_0x2861a1[a3_0x1af3('0x18')]!==a3_0x1af3('0x2b')){this[a3_0x1af3('0x40')][a3_0x1af3('0x2d')]=a3_0x1af3('0x28')+JSON[a3_0x1af3('0x33')](_0x2861a1['data']);}}else{this[a3_0x1af3('0x40')]['apiError']=a3_0x1af3('0x28')+JSON[a3_0x1af3('0x33')](_0x2861a1[a3_0x1af3('0x18')]);}if(environment_1[a3_0x1af3('0x1c')]){output[a3_0x1af3('0x5')]({'title':a3_0x1af3('0xb'),'bodyLines':[JSON[a3_0x1af3('0x33')](_0x2861a1[a3_0x1af3('0x18')],null,0x2)]});}}else{output[a3_0x1af3('0x44')]({'title':a3_0x1af3('0x16'),'bodyLines':[a3_0x1af3('0x2'),a3_0x1af3('0x9'),JSON[a3_0x1af3('0x33')](_0x2558e3,null,0x2),'Stack\x20Trace:',JSON['stringify'](new Error()[a3_0x1af3('0x2c')],null,0x2)]});}return![];}catch(_0x82f941){_0x27387c[a3_0x1af3('0x0')](((_0x1c6d17=_0x82f941===null||_0x82f941===void 0x0?void 0x0:_0x82f941[a3_0x1af3('0x14')])===null||_0x1c6d17===void 0x0?void 0x0:_0x1c6d17[a3_0x1af3('0x1f')])?(0x0,metric_logger_1[a3_0x1af3('0x43')])(_0x82f941[a3_0x1af3('0x14')][a3_0x1af3('0x1f')]):metric_logger_1['RUNNER_FAILURE_PERF_ENTRY']);const _0x1dc64b=(_0x4a0617=_0x82f941['axiosException'])!==null&&_0x4a0617!==void 0x0?_0x4a0617:_0x82f941;this[a3_0x1af3('0x40')][a3_0x1af3('0x2d')]=this[a3_0x1af3('0x40')][a3_0x1af3('0x35')](_0x1dc64b,'api');return![];}});}[a3_0x1af3('0x1')](){try{const _0x579def=JSON[a3_0x1af3('0x2f')]((0x0,fs_1['readFileSync'])('package.json')[a3_0x1af3('0xe')]());return _0x579def['devDependencies'][a3_0x1af3('0x27')];}catch(_0x149cda){return a3_0x1af3('0x13');}}}exports[a3_0x1af3('0x31')]=CloudRunApi;
@@ -1,16 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateUniqueLinkId = void 0;
4
- const upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
5
- const digits = '0123456789';
6
- const lower = upper.toLowerCase();
7
- const alphanum = upper + lower + digits;
8
- function generateUniqueLinkId() {
9
- let res = '';
10
- for (let i = 0; i < 10; ++i) {
11
- res += alphanum[Math.floor(Math.random() * alphanum.length)];
12
- }
13
- return res;
14
- }
15
- exports.generateUniqueLinkId = generateUniqueLinkId;
16
- //# sourceMappingURL=id-generator.js.map
1
+ const a4_0x507c=['length','toLowerCase','0123456789','defineProperty','ABCDEFGHIJKLMNOPQRSTUVWXYZ','generateUniqueLinkId'];(function(_0x1abab8,_0x507cc4){const _0x554597=function(_0xc78961){while(--_0xc78961){_0x1abab8['push'](_0x1abab8['shift']());}};_0x554597(++_0x507cc4);}(a4_0x507c,0xd4));const a4_0x5545=function(_0x1abab8,_0x507cc4){_0x1abab8=_0x1abab8-0x0;let _0x554597=a4_0x507c[_0x1abab8];return _0x554597;};'use strict';Object[a4_0x5545('0x1')](exports,'__esModule',{'value':!![]});exports[a4_0x5545('0x3')]=void 0x0;const upper=a4_0x5545('0x2');const digits=a4_0x5545('0x0');const lower=upper[a4_0x5545('0x5')]();const alphanum=upper+lower+digits;function generateUniqueLinkId(){let _0x1ddea4='';for(let _0x55a60f=0x0;_0x55a60f<0xa;++_0x55a60f){_0x1ddea4+=alphanum[Math['floor'](Math['random']()*alphanum[a4_0x5545('0x4')])];}return _0x1ddea4;}exports[a4_0x5545('0x3')]=generateUniqueLinkId;
@@ -1,80 +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.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, targets) {
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
- targets,
35
- }));
36
- recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(res));
37
- return res.data;
38
- }
39
- catch (e) {
40
- recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
41
- ? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
42
- : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
43
- throw e;
44
- }
45
- });
46
- }
47
- completeRunGroupWithError(error) {
48
- var _a;
49
- return __awaiter(this, void 0, void 0, function* () {
50
- if (environment_1.VERBOSE_LOGGING) {
51
- output.note({
52
- title: 'Completing run group with an error',
53
- bodyLines: [`runGroup: ${this.runGroup}`, `error: ${error}`],
54
- });
55
- }
56
- const recorder = (0, metric_logger_1.createMetricRecorder)('completeRunGroup');
57
- try {
58
- const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/complete-run-group', {
59
- runGroup: this.runGroup,
60
- agentName: this.agentName,
61
- criticalErrorMessage: error,
62
- }));
63
- if (environment_1.VERBOSE_LOGGING) {
64
- output.note({
65
- title: 'Completed run group with an error',
66
- });
67
- }
68
- recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
69
- }
70
- catch (e) {
71
- recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
72
- ? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
73
- : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
74
- console.error(e);
75
- }
76
- });
77
- }
78
- }
79
- exports.DistributedAgentApi = DistributedAgentApi;
80
- //# sourceMappingURL=distributed-agent.api.js.map
1
+ const a5_0x52bf=['Completing\x20run\x20group\x20with\x20an\x20error','tasks','../../../utilities/axios','runGroup:\x20','error:\x20','recordMetric','note','throw','data','../../../utilities/metric-logger','response','__esModule','done','../../../utilities/environment','mapRespToPerfEntry','Completed\x20run\x20group\x20with\x20an\x20error','post','agentName','completeRunGroup','apply','VERBOSE_LOGGING','runGroup','createApiAxiosInstance','then','apiAxiosInstance','axiosException','__awaiter','error','/nx-cloud/executions/tasks','value','axiosMultipleTries'];(function(_0x5c6c84,_0x52bf89){const _0x3f2f79=function(_0x2c611a){while(--_0x2c611a){_0x5c6c84['push'](_0x5c6c84['shift']());}};_0x3f2f79(++_0x52bf89);}(a5_0x52bf,0x1e8));const a5_0x3f2f=function(_0x5c6c84,_0x52bf89){_0x5c6c84=_0x5c6c84-0x0;let _0x3f2f79=a5_0x52bf[_0x5c6c84];return _0x3f2f79;};'use strict';var __awaiter=this&&this[a5_0x3f2f('0x3')]||function(_0x79e129,_0x2569c1,_0x3659be,_0x24afa4){function _0x2637e0(_0x224b78){return _0x224b78 instanceof _0x3659be?_0x224b78:new _0x3659be(function(_0x135813){_0x135813(_0x224b78);});}return new(_0x3659be||(_0x3659be=Promise))(function(_0x5a91b6,_0x29a7dd){function _0x4166d8(_0x31405e){try{_0x181590(_0x24afa4['next'](_0x31405e));}catch(_0x36c66e){_0x29a7dd(_0x36c66e);}}function _0xb4d207(_0x422746){try{_0x181590(_0x24afa4[a5_0x3f2f('0xf')](_0x422746));}catch(_0x36eb1a){_0x29a7dd(_0x36eb1a);}}function _0x181590(_0x1cac20){_0x1cac20[a5_0x3f2f('0x14')]?_0x5a91b6(_0x1cac20[a5_0x3f2f('0x6')]):_0x2637e0(_0x1cac20['value'])[a5_0x3f2f('0x0')](_0x4166d8,_0xb4d207);}_0x181590((_0x24afa4=_0x24afa4[a5_0x3f2f('0x1b')](_0x79e129,_0x2569c1||[]))['next']());});};Object['defineProperty'](exports,a5_0x3f2f('0x13'),{'value':!![]});exports['DistributedAgentApi']=void 0x0;const axios_1=require(a5_0x3f2f('0xa'));const environment_1=require(a5_0x3f2f('0x15'));const metric_logger_1=require(a5_0x3f2f('0x11'));const {output}=require('../../../utilities/nx-imports');class DistributedAgentApi{constructor(_0x551a85,_0xa5714d,_0x24bfea){this[a5_0x3f2f('0x1d')]=_0xa5714d;this[a5_0x3f2f('0x19')]=_0x24bfea;this[a5_0x3f2f('0x1')]=(0x0,axios_1[a5_0x3f2f('0x1e')])(_0x551a85);}[a5_0x3f2f('0x9')](_0x34a7a1,_0xd466f2,_0x5adef7,_0x2f582c){var _0x22c158;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x2fe11c=(0x0,metric_logger_1['createMetricRecorder'])('dtePollTasks');try{const _0x47c1e3=yield(0x0,axios_1[a5_0x3f2f('0x7')])(()=>this[a5_0x3f2f('0x1')]['post'](a5_0x3f2f('0x5'),{'runGroup':this[a5_0x3f2f('0x1d')],'agentName':this[a5_0x3f2f('0x19')],'executionId':_0x34a7a1,'statusCode':_0xd466f2,'completedTasks':_0x5adef7,'targets':_0x2f582c}));_0x2fe11c[a5_0x3f2f('0xd')]((0x0,metric_logger_1[a5_0x3f2f('0x16')])(_0x47c1e3));return _0x47c1e3[a5_0x3f2f('0x10')];}catch(_0x2f54ff){_0x2fe11c['recordMetric'](((_0x22c158=_0x2f54ff===null||_0x2f54ff===void 0x0?void 0x0:_0x2f54ff[a5_0x3f2f('0x2')])===null||_0x22c158===void 0x0?void 0x0:_0x22c158[a5_0x3f2f('0x12')])?(0x0,metric_logger_1[a5_0x3f2f('0x16')])(_0x2f54ff[a5_0x3f2f('0x2')][a5_0x3f2f('0x12')]):metric_logger_1['RUNNER_FAILURE_PERF_ENTRY']);throw _0x2f54ff;}});}['completeRunGroupWithError'](_0x3d0ab7){var _0x295bc2;return __awaiter(this,void 0x0,void 0x0,function*(){if(environment_1[a5_0x3f2f('0x1c')]){output[a5_0x3f2f('0xe')]({'title':a5_0x3f2f('0x8'),'bodyLines':[a5_0x3f2f('0xb')+this[a5_0x3f2f('0x1d')],a5_0x3f2f('0xc')+_0x3d0ab7]});}const _0x4888bc=(0x0,metric_logger_1['createMetricRecorder'])(a5_0x3f2f('0x1a'));try{const _0x214676=yield(0x0,axios_1['axiosMultipleTries'])(()=>this[a5_0x3f2f('0x1')][a5_0x3f2f('0x18')]('/nx-cloud/executions/complete-run-group',{'runGroup':this[a5_0x3f2f('0x1d')],'agentName':this[a5_0x3f2f('0x19')],'criticalErrorMessage':_0x3d0ab7}));if(environment_1['VERBOSE_LOGGING']){output['note']({'title':a5_0x3f2f('0x17')});}_0x4888bc['recordMetric']((0x0,metric_logger_1[a5_0x3f2f('0x16')])(_0x214676));}catch(_0x3030c3){_0x4888bc[a5_0x3f2f('0xd')](((_0x295bc2=_0x3030c3===null||_0x3030c3===void 0x0?void 0x0:_0x3030c3['axiosException'])===null||_0x295bc2===void 0x0?void 0x0:_0x295bc2[a5_0x3f2f('0x12')])?(0x0,metric_logger_1['mapRespToPerfEntry'])(_0x3030c3[a5_0x3f2f('0x2')][a5_0x3f2f('0x12')]):metric_logger_1['RUNNER_FAILURE_PERF_ENTRY']);console[a5_0x3f2f('0x4')](_0x3030c3);}});}}exports['DistributedAgentApi']=DistributedAgentApi;
@@ -1,154 +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 fs_1 = require("fs");
14
- const stripJsonComments = require("strip-json-comments");
15
- const yargsParser = require("yargs-parser");
16
- const environment_1 = require("../../../utilities/environment");
17
- const metric_logger_1 = require("../../../utilities/metric-logger");
18
- const print_cacheable_targets_error_1 = require("../../error/print-cacheable-targets-error");
19
- const print_invalid_runner_error_1 = require("../../error/print-invalid-runner-error");
20
- const print_run_group_error_1 = require("../../error/print-run-group-error");
21
- const distributed_agent_api_1 = require("./distributed-agent.api");
22
- const execute_tasks_1 = require("./execute-tasks");
23
- const dte_artifact_storage_1 = require("../../../utilities/dte-artifact-storage");
24
- const file_storage_1 = require("../../file-storage/file-storage");
25
- const e2e_encryption_1 = require("../../file-storage/e2e-encryption");
26
- const error_reporter_api_1 = require("../../api/error-reporter.api");
27
- const invoke_tasks_using_run_many_1 = require("./invoke-tasks-using-run-many");
28
- const invoke_tasks_using_nx_imperative_api_1 = require("./invoke-tasks-using-nx-imperative-api");
29
- const { output, initTasksRunner, workspaceRoot, } = require('../../../utilities/nx-imports');
30
- const args = yargsParser(process.argv, {
31
- array: ['targets'],
32
- default: {},
33
- });
34
- // just in case someone passes the args with commas
35
- // cf. https://github.com/yargs/yargs/issues/846
36
- if (args.targets && args.targets.length === 1) {
37
- args.targets = args.targets[0].split(',').map((x) => x.trim());
38
- }
39
- function startAgent() {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- const runGroup = (0, environment_1.getRunGroup)();
42
- if (!runGroup) {
43
- (0, print_run_group_error_1.printRunGroupError)();
44
- return process.exit(1);
45
- }
46
- if (args.targets && args.targets.length) {
47
- output.note({
48
- title: `Starting an agent for running Nx target(s) [${args.targets.join(', ')}]`,
49
- });
50
- }
51
- else {
52
- output.note({
53
- title: 'Starting an agent for running Nx tasks',
54
- });
55
- }
56
- const defaultRunnerConfig = JSON.parse(stripJsonComments((0, fs_1.readFileSync)(`${workspaceRoot}/nx.json`).toString())).tasksRunnerOptions.default;
57
- if (defaultRunnerConfig.runner !== '@nrwl/nx-cloud') {
58
- (0, print_invalid_runner_error_1.printInvalidRunnerError)();
59
- return process.exit(1);
60
- }
61
- const options = defaultRunnerConfig.options;
62
- if (args.targets &&
63
- args.targets.some((target) => { var _a; return !((_a = options.cacheableOperations) === null || _a === void 0 ? void 0 : _a.includes(target)); })) {
64
- const wrongTargets = args.targets.filter((target) => { var _a; return !((_a = options.cacheableOperations) === null || _a === void 0 ? void 0 : _a.includes(target)); });
65
- (0, print_cacheable_targets_error_1.printCacheableTargetsError)(wrongTargets);
66
- return process.exit(1);
67
- }
68
- const agentName = getAgentName();
69
- const api = new distributed_agent_api_1.DistributedAgentApi(options, runGroup, agentName);
70
- createAgentLockfileAndSetUpListeners(api, options, agentName);
71
- const encryption = new e2e_encryption_1.E2EEncryption(environment_1.ENCRYPTION_KEY || options.encryptionKey);
72
- const errorReporter = new error_reporter_api_1.ErrorReporterApi(options);
73
- const dteArtifactStorage = new dte_artifact_storage_1.DteArtifactStorage(new file_storage_1.FileStorage(encryption, errorReporter), (0, environment_1.getNxCacheDirectory)(options));
74
- const invokeTasks = initTasksRunner
75
- ? yield (0, invoke_tasks_using_nx_imperative_api_1.invokeTasksUsingNxImperativeApi)(options)
76
- : yield (0, invoke_tasks_using_run_many_1.invokeTasksUsingRunMany)(options);
77
- return (0, execute_tasks_1.executeTasks)(agentName, api, dteArtifactStorage, invokeTasks, args.targets)
78
- .then((res) => __awaiter(this, void 0, void 0, function* () {
79
- yield (0, metric_logger_1.submitRunMetrics)(options);
80
- return res;
81
- }))
82
- .catch((e) => __awaiter(this, void 0, void 0, function* () {
83
- yield api.completeRunGroupWithError(`Critical Error in Agent: "${e.message}"`);
84
- throw e;
85
- }));
86
- });
87
- }
88
- exports.startAgent = startAgent;
89
- function getAgentName() {
90
- if (process.env.NX_AGENT_NAME !== undefined) {
91
- return process.env.NX_AGENT_NAME;
92
- }
93
- else if (process.env.CIRCLECI !== undefined && process.env.CIRCLE_STAGE) {
94
- return process.env.CIRCLE_STAGE;
95
- }
96
- else if (process.env.CIRCLECI !== undefined && process.env.CIRCLE_JOB) {
97
- return process.env.CIRCLE_JOB;
98
- }
99
- else {
100
- return `Agent ${Math.floor(Math.random() * 100000)}`;
101
- }
102
- }
103
- function createAgentLockfileAndSetUpListeners(api, options, agentName) {
104
- const cacheDirectory = (0, environment_1.getNxCacheDirectory)(options);
105
- const lockFileDirectory = `${cacheDirectory}/lockfiles`;
106
- const lockFilePath = `${lockFileDirectory}/${agentName}.lock`;
107
- if (!(0, fs_1.existsSync)(lockFileDirectory)) {
108
- (0, fs_1.mkdirSync)(lockFileDirectory, { recursive: true });
109
- }
110
- // Check for other agents' lockfiles and warn if exist
111
- const lockFiles = (0, fs_1.readdirSync)(lockFileDirectory);
112
- if (lockFiles.length) {
113
- // Check to make sure the current agent name is not in use (only 1/100000 ^ 2 chance of this)
114
- if (lockFiles.includes(`${agentName}.lock`)) {
115
- output.error({
116
- title: 'Duplicate Agent ID Detected',
117
- bodyLines: [
118
- 'We have detected another agent with this ID running in this workspace. This should not happen.',
119
- '',
120
- 'End all currently running agents, run "npx nx-cloud clean-up-agents", and try again.',
121
- ],
122
- });
123
- process.exit(1);
124
- }
125
- output.warn({
126
- title: 'Other Nx Cloud Agents Detected',
127
- bodyLines: [
128
- 'We have detected other agents running in this workspace. This can cause unexpected behavior.',
129
- '',
130
- 'This can also be a false positive caused by agents that did not shut down correctly.',
131
- 'If you believe this is the case, run "npx nx-cloud clean-up-agents".',
132
- ],
133
- });
134
- }
135
- (0, fs_1.writeFileSync)(lockFilePath, '');
136
- process.on('exit', (code) => {
137
- cleanupAgentLockfile(lockFilePath, code);
138
- });
139
- process.on('SIGTERM', () => __awaiter(this, void 0, void 0, function* () {
140
- yield api.completeRunGroupWithError('Agent was terminated via SIGTERM');
141
- cleanupAgentLockfile(lockFilePath, 1);
142
- }));
143
- process.on('SIGINT', () => __awaiter(this, void 0, void 0, function* () {
144
- yield api.completeRunGroupWithError('Agent was terminated via SIGINT');
145
- cleanupAgentLockfile(lockFilePath, 1);
146
- }));
147
- }
148
- function cleanupAgentLockfile(lockFilePath, code) {
149
- if ((0, fs_1.existsSync)(lockFilePath)) {
150
- (0, fs_1.unlinkSync)(lockFilePath);
151
- process.exit(code);
152
- }
153
- }
154
- //# sourceMappingURL=distributed-agent.impl.js.map
1
+ const a6_0x30df=['invokeTasksUsingNxImperativeApi','./invoke-tasks-using-run-many','CIRCLE_STAGE','value','exit','trim','__awaiter','../../../utilities/dte-artifact-storage','encryptionKey','parse','__esModule','printInvalidRunnerError','getNxCacheDirectory','message','startAgent','.lock','warn','some','executeTasks','SIGINT','../../file-storage/file-storage','toString','existsSync','End\x20all\x20currently\x20running\x20agents,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22,\x20and\x20try\x20again.','includes','then','map','../../../utilities/environment','yargs-parser','throw','targets','readFileSync','random','readdirSync','/lockfiles','completeRunGroupWithError','env','argv','../../api/error-reporter.api','Starting\x20an\x20agent\x20for\x20running\x20Nx\x20target(s)\x20[','This\x20can\x20also\x20be\x20a\x20false\x20positive\x20caused\x20by\x20agents\x20that\x20did\x20not\x20shut\x20down\x20correctly.','/nx.json','length','../../file-storage/e2e-encryption','Agent\x20','next','E2EEncryption','We\x20have\x20detected\x20another\x20agent\x20with\x20this\x20ID\x20running\x20in\x20this\x20workspace.\x20This\x20should\x20not\x20happen.','filter','../../error/print-cacheable-targets-error','tasksRunnerOptions','ENCRYPTION_KEY','DteArtifactStorage','CIRCLECI','CIRCLE_JOB','floor','runner','ErrorReporterApi','../../../utilities/metric-logger','note','FileStorage','../../../utilities/nx-imports','Agent\x20was\x20terminated\x20via\x20SIGTERM','We\x20have\x20detected\x20other\x20agents\x20running\x20in\x20this\x20workspace.\x20This\x20can\x20cause\x20unexpected\x20behavior.','SIGTERM','strip-json-comments','NX_AGENT_NAME','printCacheableTargetsError','error','Agent\x20was\x20terminated\x20via\x20SIGINT','catch','cacheableOperations','@nrwl/nx-cloud','done','DistributedAgentApi','../../error/print-invalid-runner-error'];(function(_0x2eb675,_0x30df9d){const _0x1d3618=function(_0x3878a2){while(--_0x3878a2){_0x2eb675['push'](_0x2eb675['shift']());}};_0x1d3618(++_0x30df9d);}(a6_0x30df,0x128));const a6_0x1d36=function(_0x2eb675,_0x30df9d){_0x2eb675=_0x2eb675-0x0;let _0x1d3618=a6_0x30df[_0x2eb675];return _0x1d3618;};'use strict';var __awaiter=this&&this[a6_0x1d36('0xe')]||function(_0x548681,_0x1837d6,_0x2afd7d,_0x44766d){function _0x1007e5(_0x5cab23){return _0x5cab23 instanceof _0x2afd7d?_0x5cab23:new _0x2afd7d(function(_0x4bab0b){_0x4bab0b(_0x5cab23);});}return new(_0x2afd7d||(_0x2afd7d=Promise))(function(_0x4d1664,_0x54870d){function _0x48b040(_0xf74f22){try{_0x99304(_0x44766d[a6_0x1d36('0x35')](_0xf74f22));}catch(_0x207fbd){_0x54870d(_0x207fbd);}}function _0x37a932(_0x161197){try{_0x99304(_0x44766d[a6_0x1d36('0x25')](_0x161197));}catch(_0x524407){_0x54870d(_0x524407);}}function _0x99304(_0x45c271){_0x45c271[a6_0x1d36('0x5')]?_0x4d1664(_0x45c271['value']):_0x1007e5(_0x45c271[a6_0x1d36('0xb')])['then'](_0x48b040,_0x37a932);}_0x99304((_0x44766d=_0x44766d['apply'](_0x548681,_0x1837d6||[]))[a6_0x1d36('0x35')]());});};Object['defineProperty'](exports,a6_0x1d36('0x12'),{'value':!![]});exports[a6_0x1d36('0x16')]=void 0x0;const fs_1=require('fs');const stripJsonComments=require(a6_0x1d36('0x49'));const yargsParser=require(a6_0x1d36('0x24'));const environment_1=require(a6_0x1d36('0x23'));const metric_logger_1=require(a6_0x1d36('0x42'));const print_cacheable_targets_error_1=require(a6_0x1d36('0x39'));const print_invalid_runner_error_1=require(a6_0x1d36('0x7'));const print_run_group_error_1=require('../../error/print-run-group-error');const distributed_agent_api_1=require('./distributed-agent.api');const execute_tasks_1=require('./execute-tasks');const dte_artifact_storage_1=require(a6_0x1d36('0xf'));const file_storage_1=require(a6_0x1d36('0x1c'));const e2e_encryption_1=require(a6_0x1d36('0x33'));const error_reporter_api_1=require(a6_0x1d36('0x2e'));const invoke_tasks_using_run_many_1=require(a6_0x1d36('0x9'));const invoke_tasks_using_nx_imperative_api_1=require('./invoke-tasks-using-nx-imperative-api');const {output,initTasksRunner,workspaceRoot}=require(a6_0x1d36('0x45'));const args=yargsParser(process[a6_0x1d36('0x2d')],{'array':[a6_0x1d36('0x26')],'default':{}});if(args[a6_0x1d36('0x26')]&&args[a6_0x1d36('0x26')][a6_0x1d36('0x32')]===0x1){args[a6_0x1d36('0x26')]=args[a6_0x1d36('0x26')][0x0]['split'](',')[a6_0x1d36('0x22')](_0x20b45a=>_0x20b45a[a6_0x1d36('0xd')]());}function startAgent(){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x50b05d=(0x0,environment_1['getRunGroup'])();if(!_0x50b05d){(0x0,print_run_group_error_1['printRunGroupError'])();return process[a6_0x1d36('0xc')](0x1);}if(args[a6_0x1d36('0x26')]&&args[a6_0x1d36('0x26')][a6_0x1d36('0x32')]){output[a6_0x1d36('0x43')]({'title':a6_0x1d36('0x2f')+args['targets']['join'](',\x20')+']'});}else{output['note']({'title':'Starting\x20an\x20agent\x20for\x20running\x20Nx\x20tasks'});}const _0x147733=JSON[a6_0x1d36('0x11')](stripJsonComments((0x0,fs_1[a6_0x1d36('0x27')])(workspaceRoot+a6_0x1d36('0x31'))[a6_0x1d36('0x1d')]()))[a6_0x1d36('0x3a')]['default'];if(_0x147733[a6_0x1d36('0x40')]!==a6_0x1d36('0x4')){(0x0,print_invalid_runner_error_1[a6_0x1d36('0x13')])();return process[a6_0x1d36('0xc')](0x1);}const _0x582142=_0x147733['options'];if(args[a6_0x1d36('0x26')]&&args[a6_0x1d36('0x26')][a6_0x1d36('0x19')](_0x11af80=>{var _0xf43ba;return!((_0xf43ba=_0x582142[a6_0x1d36('0x3')])===null||_0xf43ba===void 0x0?void 0x0:_0xf43ba['includes'](_0x11af80));})){const _0x2391c0=args[a6_0x1d36('0x26')][a6_0x1d36('0x38')](_0xc54802=>{var _0x43d1b9;return!((_0x43d1b9=_0x582142[a6_0x1d36('0x3')])===null||_0x43d1b9===void 0x0?void 0x0:_0x43d1b9[a6_0x1d36('0x20')](_0xc54802));});(0x0,print_cacheable_targets_error_1[a6_0x1d36('0x4b')])(_0x2391c0);return process[a6_0x1d36('0xc')](0x1);}const _0x3717d9=getAgentName();const _0x253cf3=new distributed_agent_api_1[(a6_0x1d36('0x6'))](_0x582142,_0x50b05d,_0x3717d9);createAgentLockfileAndSetUpListeners(_0x253cf3,_0x582142,_0x3717d9);const _0x65b827=new e2e_encryption_1[(a6_0x1d36('0x36'))](environment_1[a6_0x1d36('0x3b')]||_0x582142[a6_0x1d36('0x10')]);const _0x3249af=new error_reporter_api_1[(a6_0x1d36('0x41'))](_0x582142);const _0x413751=new dte_artifact_storage_1[(a6_0x1d36('0x3c'))](new file_storage_1[(a6_0x1d36('0x44'))](_0x65b827,_0x3249af),(0x0,environment_1[a6_0x1d36('0x14')])(_0x582142));const _0x4c0aaf=initTasksRunner?yield(0x0,invoke_tasks_using_nx_imperative_api_1[a6_0x1d36('0x8')])(_0x582142):yield(0x0,invoke_tasks_using_run_many_1['invokeTasksUsingRunMany'])(_0x582142);return(0x0,execute_tasks_1[a6_0x1d36('0x1a')])(_0x3717d9,_0x253cf3,_0x413751,_0x4c0aaf,args['targets'])[a6_0x1d36('0x21')](_0xfb60ba=>__awaiter(this,void 0x0,void 0x0,function*(){yield(0x0,metric_logger_1['submitRunMetrics'])(_0x582142);return _0xfb60ba;}))[a6_0x1d36('0x2')](_0x16f612=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x253cf3[a6_0x1d36('0x2b')]('Critical\x20Error\x20in\x20Agent:\x20\x22'+_0x16f612[a6_0x1d36('0x15')]+'\x22');throw _0x16f612;}));});}exports['startAgent']=startAgent;function getAgentName(){if(process[a6_0x1d36('0x2c')][a6_0x1d36('0x4a')]!==undefined){return process['env'][a6_0x1d36('0x4a')];}else if(process['env']['CIRCLECI']!==undefined&&process['env'][a6_0x1d36('0xa')]){return process[a6_0x1d36('0x2c')][a6_0x1d36('0xa')];}else if(process['env'][a6_0x1d36('0x3d')]!==undefined&&process[a6_0x1d36('0x2c')][a6_0x1d36('0x3e')]){return process[a6_0x1d36('0x2c')][a6_0x1d36('0x3e')];}else{return a6_0x1d36('0x34')+Math[a6_0x1d36('0x3f')](Math[a6_0x1d36('0x28')]()*0x186a0);}}function createAgentLockfileAndSetUpListeners(_0x56b840,_0x298580,_0x548dc9){const _0x22fd25=(0x0,environment_1[a6_0x1d36('0x14')])(_0x298580);const _0x374c06=_0x22fd25+a6_0x1d36('0x2a');const _0x286174=_0x374c06+'/'+_0x548dc9+a6_0x1d36('0x17');if(!(0x0,fs_1['existsSync'])(_0x374c06)){(0x0,fs_1['mkdirSync'])(_0x374c06,{'recursive':!![]});}const _0x12cce4=(0x0,fs_1[a6_0x1d36('0x29')])(_0x374c06);if(_0x12cce4['length']){if(_0x12cce4[a6_0x1d36('0x20')](_0x548dc9+a6_0x1d36('0x17'))){output[a6_0x1d36('0x0')]({'title':'Duplicate\x20Agent\x20ID\x20Detected','bodyLines':[a6_0x1d36('0x37'),'',a6_0x1d36('0x1f')]});process[a6_0x1d36('0xc')](0x1);}output[a6_0x1d36('0x18')]({'title':'Other\x20Nx\x20Cloud\x20Agents\x20Detected','bodyLines':[a6_0x1d36('0x47'),'',a6_0x1d36('0x30'),'If\x20you\x20believe\x20this\x20is\x20the\x20case,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22.']});}(0x0,fs_1['writeFileSync'])(_0x286174,'');process['on'](a6_0x1d36('0xc'),_0x3b1cbd=>{cleanupAgentLockfile(_0x286174,_0x3b1cbd);});process['on'](a6_0x1d36('0x48'),()=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x56b840[a6_0x1d36('0x2b')](a6_0x1d36('0x46'));cleanupAgentLockfile(_0x286174,0x1);}));process['on'](a6_0x1d36('0x1b'),()=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x56b840[a6_0x1d36('0x2b')](a6_0x1d36('0x1'));cleanupAgentLockfile(_0x286174,0x1);}));}function cleanupAgentLockfile(_0x22e460,_0x5f4f4f){if((0x0,fs_1[a6_0x1d36('0x1e')])(_0x22e460)){(0x0,fs_1['unlinkSync'])(_0x22e460);process[a6_0x1d36('0xc')](_0x5f4f4f);}}