@nrwl/nx-cloud 14.4.1 → 14.4.2-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,113 @@
1
- const a2_0x23ee=['Nx\x20Cloud:\x20Skipping\x20storing\x20','get','runContext','apply','retrieve','hashUrls','VERBOSE_LOGGING','hash','response','remote-cache-hit','waitForStoreRequestsToComplete','cache-miss','forEach','statuses','storage','status','extractErrorMessage','__awaiter','requests','then','indexOf','done','.\x20Status\x20404.','reduce','.\x20Read\x20only\x20token\x20is\x20used.','Nx\x20Cloud:\x20Cache\x20miss\x20','cacheError','value','defineProperty','../../../utilities/nx-imports','axiosException','startRun','storeRequests','messages','note','api','next','fileStorage','push','store','CloudRemoteCache','put','map','resolve'];(function(_0x1e70c9,_0x23ee20){const _0x6eea9f=function(_0x16d978){while(--_0x16d978){_0x1e70c9['push'](_0x1e70c9['shift']());}};_0x6eea9f(++_0x23ee20);}(a2_0x23ee,0xe3));const a2_0x6eea=function(_0x1e70c9,_0x23ee20){_0x1e70c9=_0x1e70c9-0x0;let _0x6eea9f=a2_0x23ee[_0x1e70c9];return _0x6eea9f;};'use strict';var __awaiter=this&&this[a2_0x6eea('0xa')]||function(_0x1a1a17,_0x1053c8,_0x27dcf1,_0x2f20a2){function _0x5e7e4b(_0x19f0b5){return _0x19f0b5 instanceof _0x27dcf1?_0x19f0b5:new _0x27dcf1(function(_0x103b84){_0x103b84(_0x19f0b5);});}return new(_0x27dcf1||(_0x27dcf1=Promise))(function(_0x2e3f8a,_0x22687a){function _0x3663f8(_0x1b20df){try{_0x59996a(_0x2f20a2['next'](_0x1b20df));}catch(_0x45f382){_0x22687a(_0x45f382);}}function _0x51972e(_0x197567){try{_0x59996a(_0x2f20a2['throw'](_0x197567));}catch(_0x32c919){_0x22687a(_0x32c919);}}function _0x59996a(_0x51ab8a){_0x51ab8a[a2_0x6eea('0xe')]?_0x2e3f8a(_0x51ab8a[a2_0x6eea('0x14')]):_0x5e7e4b(_0x51ab8a[a2_0x6eea('0x14')])['then'](_0x3663f8,_0x51972e);}_0x59996a((_0x2f20a2=_0x2f20a2[a2_0x6eea('0x28')](_0x1a1a17,_0x1053c8||[]))[a2_0x6eea('0x1d')]());});};Object[a2_0x6eea('0x15')](exports,'__esModule',{'value':!![]});exports[a2_0x6eea('0x21')]=void 0x0;const environment_1=require('../../../utilities/environment');const {output}=require(a2_0x6eea('0x16'));class CloudRemoteCache{constructor(_0x5eaa47,_0x39aa1f,_0x3cd424,_0x11fb4a){this[a2_0x6eea('0x1a')]=_0x5eaa47;this[a2_0x6eea('0x1c')]=_0x39aa1f;this[a2_0x6eea('0x27')]=_0x3cd424;this['fileStorage']=_0x11fb4a;this[a2_0x6eea('0x19')]=[];}[a2_0x6eea('0x29')](_0x200fd3,_0x2cf1af){var _0x2e0b2b;return __awaiter(this,void 0x0,void 0x0,function*(){if(this['messages'][a2_0x6eea('0x13')])return![];const _0x11f48d=yield this[a2_0x6eea('0x2a')](_0x200fd3);if(!_0x11f48d||!_0x11f48d['get']){if(environment_1[a2_0x6eea('0x2b')]){output[a2_0x6eea('0x1b')]({'title':a2_0x6eea('0x12')+_0x200fd3+'.'});}this['runContext'][a2_0x6eea('0x6')][_0x200fd3]=a2_0x6eea('0x4');return![];}try{yield this[a2_0x6eea('0x1e')]['retrieve'](_0x200fd3,_0x11f48d[a2_0x6eea('0x26')],_0x2cf1af);this[a2_0x6eea('0x27')][a2_0x6eea('0x6')][_0x200fd3]=a2_0x6eea('0x2');return!![];}catch(_0x152010){const _0x23e12d=(_0x2e0b2b=_0x152010[a2_0x6eea('0x17')])!==null&&_0x2e0b2b!==void 0x0?_0x2e0b2b:_0x152010;if(_0x23e12d[a2_0x6eea('0x1')]&&_0x23e12d[a2_0x6eea('0x1')][a2_0x6eea('0x8')]===0x194){if(environment_1[a2_0x6eea('0x2b')]){output[a2_0x6eea('0x1b')]({'title':a2_0x6eea('0x12')+_0x200fd3+a2_0x6eea('0xf')});}}else{this['messages'][a2_0x6eea('0x13')]=this[a2_0x6eea('0x1a')]['extractErrorMessage'](_0x23e12d,'storage');}this[a2_0x6eea('0x27')]['statuses'][_0x200fd3]=a2_0x6eea('0x4');return![];}});}['store'](_0x3cb8a1,_0x3fdd85){return __awaiter(this,void 0x0,void 0x0,function*(){if(this[a2_0x6eea('0x1a')][a2_0x6eea('0x13')])return![];const _0x3812bf=Promise[a2_0x6eea('0x24')]()[a2_0x6eea('0xc')](()=>__awaiter(this,void 0x0,void 0x0,function*(){var _0x3526c0;const _0x25c9d1=yield this[a2_0x6eea('0x2a')](_0x3cb8a1);if(!_0x25c9d1)return![];if(!_0x25c9d1[a2_0x6eea('0x22')]){if(environment_1['VERBOSE_LOGGING']){output[a2_0x6eea('0x1b')]({'title':a2_0x6eea('0x25')+_0x3cb8a1+a2_0x6eea('0x11')});}return!![];}try{yield this[a2_0x6eea('0x1e')][a2_0x6eea('0x20')](_0x3cb8a1,_0x25c9d1[a2_0x6eea('0x22')],_0x3fdd85);return!![];}catch(_0x309a87){const _0x82d647=(_0x3526c0=_0x309a87[a2_0x6eea('0x17')])!==null&&_0x3526c0!==void 0x0?_0x3526c0:_0x309a87;this['messages'][a2_0x6eea('0x13')]=this[a2_0x6eea('0x1a')][a2_0x6eea('0x9')](_0x82d647,a2_0x6eea('0x7'));return![];}}));this[a2_0x6eea('0x19')][a2_0x6eea('0x1f')](_0x3812bf);return _0x3812bf;});}['hashUrls'](_0x58129b){return __awaiter(this,void 0x0,void 0x0,function*(){if(_0x58129b in this[a2_0x6eea('0x27')][a2_0x6eea('0xb')]){return(yield this[a2_0x6eea('0x27')][a2_0x6eea('0xb')][_0x58129b])[_0x58129b];}else{const _0x2aef4d=this['runContext']['scheduledTasks']['filter'](_0x2fd0f6=>!this[a2_0x6eea('0x27')]['requests'][_0x2fd0f6['hash']])[a2_0x6eea('0x23')](_0x195ab2=>_0x195ab2[a2_0x6eea('0x0')]);if(_0x2aef4d[a2_0x6eea('0xd')](_0x58129b)===-0x1){_0x2aef4d[a2_0x6eea('0x1f')](_0x58129b);}const _0x22d54a=this[a2_0x6eea('0x1c')][a2_0x6eea('0x18')](environment_1['NX_CLOUD_DISTRIBUTED_EXECUTION_ID'],_0x2aef4d);_0x2aef4d[a2_0x6eea('0x5')](_0x41d5ed=>{this[a2_0x6eea('0x27')][a2_0x6eea('0xb')][_0x41d5ed]=_0x22d54a;});return(yield _0x22d54a)[_0x58129b];}});}[a2_0x6eea('0x3')](){return Promise['all'](this[a2_0x6eea('0x19')])[a2_0x6eea('0xc')](_0x3536b0=>_0x3536b0[a2_0x6eea('0x10')]((_0x322e7e,_0x4054ef)=>_0x322e7e&&_0x4054ef,!![]));}}exports[a2_0x6eea('0x21')]=CloudRemoteCache;
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) {
17
+ this.messages = messages;
18
+ this.api = api;
19
+ this.runContext = runContext;
20
+ this.fileStorage = fileStorage;
21
+ this.storeRequests = [];
22
+ }
23
+ retrieve(hash, cacheDirectory) {
24
+ var _a;
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ if (this.messages.cacheError)
27
+ return false;
28
+ const hashUrls = yield this.hashUrls(hash);
29
+ if (!hashUrls || !hashUrls.get) {
30
+ if (environment_1.VERBOSE_LOGGING) {
31
+ output.note({ title: `Nx Cloud: Cache miss ${hash}.` });
32
+ }
33
+ this.runContext.statuses[hash] = 'cache-miss';
34
+ return false;
35
+ }
36
+ try {
37
+ yield this.fileStorage.retrieve(hash, hashUrls.get, cacheDirectory);
38
+ this.runContext.statuses[hash] = 'remote-cache-hit';
39
+ return true;
40
+ }
41
+ catch (ee) {
42
+ const e = (_a = ee.axiosException) !== null && _a !== void 0 ? _a : ee;
43
+ if (e.response && e.response.status === 404) {
44
+ if (environment_1.VERBOSE_LOGGING) {
45
+ output.note({ title: `Nx Cloud: Cache miss ${hash}. Status 404.` });
46
+ }
47
+ // cache miss. print nothing
48
+ }
49
+ else {
50
+ this.messages.cacheError = this.messages.extractErrorMessage(e, 'storage');
51
+ }
52
+ this.runContext.statuses[hash] = 'cache-miss';
53
+ return false;
54
+ }
55
+ });
56
+ }
57
+ store(hash, cacheDirectory) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ if (this.messages.cacheError)
60
+ return false;
61
+ const res = Promise.resolve().then(() => __awaiter(this, void 0, void 0, function* () {
62
+ var _a;
63
+ const hashUrls = yield this.hashUrls(hash);
64
+ if (!hashUrls)
65
+ return false;
66
+ if (!hashUrls.put) {
67
+ if (environment_1.VERBOSE_LOGGING) {
68
+ output.note({
69
+ title: `Nx Cloud: Skipping storing ${hash}. Read only token is used.`,
70
+ });
71
+ }
72
+ return true;
73
+ }
74
+ try {
75
+ yield this.fileStorage.store(hash, hashUrls.put, cacheDirectory);
76
+ return true;
77
+ }
78
+ catch (ee) {
79
+ const e = (_a = ee.axiosException) !== null && _a !== void 0 ? _a : ee;
80
+ this.messages.cacheError = this.messages.extractErrorMessage(e, 'storage');
81
+ return false;
82
+ }
83
+ }));
84
+ this.storeRequests.push(res);
85
+ return res;
86
+ });
87
+ }
88
+ hashUrls(hash) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ if (hash in this.runContext.requests) {
91
+ return (yield this.runContext.requests[hash])[hash];
92
+ }
93
+ else {
94
+ const scheduledTaskHashesWithoutRequests = this.runContext.scheduledTasks
95
+ .filter((t) => !this.runContext.requests[t.hash])
96
+ .map((t) => t.hash);
97
+ if (scheduledTaskHashesWithoutRequests.indexOf(hash) === -1) {
98
+ scheduledTaskHashesWithoutRequests.push(hash);
99
+ }
100
+ const request = this.api.startRun(environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_ID, scheduledTaskHashesWithoutRequests);
101
+ scheduledTaskHashesWithoutRequests.forEach((taskHash) => {
102
+ this.runContext.requests[taskHash] = request;
103
+ });
104
+ return (yield request)[hash];
105
+ }
106
+ });
107
+ }
108
+ waitForStoreRequestsToComplete() {
109
+ return Promise.all(this.storeRequests).then((r) => r.reduce((a, b) => a && b, true));
110
+ }
111
+ }
112
+ exports.CloudRemoteCache = CloudRemoteCache;
113
+ //# sourceMappingURL=cloud-remote-cache.js.map
@@ -1 +1,166 @@
1
- const a3_0x2a3c=['apply','runContext','post','headers','machineInfo','defineProperty','error','gzip','value','@nrwl/nx-cloud','terminalOutput','Run\x20Details:','../../../utilities/nx-imports','note','devDependencies','../../../utilities/environment','response','package.json','extractErrorMessage','createMetricRecorder','CloudRunApi','endRun','then','startRun','stringify','assign','string','api','Nx\x20Cloud:\x20Unknown\x20Error\x20Occurred','createReqBody','RunStart','zlib','success','unknown','status','/nx-cloud/runs/start','__esModule','createApiAxiosInstance','length','next','apiError','VERBOSE_LOGGING','message','urls','__awaiter','../../../utilities/axios','nxCloudVersion','Invalid\x20end\x20run\x20response','Run\x20completion\x20responded\x20with\x20`undefined`.','defaults','axiosMultipleTries','Invalid\x20end\x20run\x20response:\x20','util','recordMetric','getRunGroup','apiAxiosInstance','RunEnd.\x20Completed\x20tasks','axiosException','Stack\x20Trace:','parse','mapRespToPerfEntry','application/octet-stream','throw','runUrl','toString','messages','data','stack','RUNNER_FAILURE_PERF_ENTRY','map'];(function(_0x528916,_0x2a3c80){const _0x5c82d6=function(_0x1b8046){while(--_0x1b8046){_0x528916['push'](_0x528916['shift']());}};_0x5c82d6(++_0x2a3c80);}(a3_0x2a3c,0x1bf));const a3_0x5c82=function(_0x528916,_0x2a3c80){_0x528916=_0x528916-0x0;let _0x5c82d6=a3_0x2a3c[_0x528916];return _0x5c82d6;};'use strict';var __awaiter=this&&this[a3_0x5c82('0x11')]||function(_0x2a1df3,_0x414405,_0x2cdffe,_0x5c6e6b){function _0x58bcb2(_0x454696){return _0x454696 instanceof _0x2cdffe?_0x454696:new _0x2cdffe(function(_0x15135c){_0x15135c(_0x454696);});}return new(_0x2cdffe||(_0x2cdffe=Promise))(function(_0x4bb845,_0x548f70){function _0x43886a(_0x5dec3a){try{_0x171681(_0x5c6e6b[a3_0x5c82('0xc')](_0x5dec3a));}catch(_0x4281ca){_0x548f70(_0x4281ca);}}function _0x12750e(_0x4615e0){try{_0x171681(_0x5c6e6b[a3_0x5c82('0x23')](_0x4615e0));}catch(_0x2afe81){_0x548f70(_0x2afe81);}}function _0x171681(_0x4be5b0){_0x4be5b0['done']?_0x4bb845(_0x4be5b0[a3_0x5c82('0x33')]):_0x58bcb2(_0x4be5b0['value'])[a3_0x5c82('0x41')](_0x43886a,_0x12750e);}_0x171681((_0x5c6e6b=_0x5c6e6b[a3_0x5c82('0x2b')](_0x2a1df3,_0x414405||[]))['next']());});};Object[a3_0x5c82('0x30')](exports,a3_0x5c82('0x9'),{'value':!![]});exports['CloudRunApi']=void 0x0;const axios_1=require(a3_0x5c82('0x12'));const environment_1=require(a3_0x5c82('0x3a'));const fs_1=require('fs');const zlib_1=require(a3_0x5c82('0x4'));const util_1=require(a3_0x5c82('0x19'));const metric_logger_1=require('../../../utilities/metric-logger');const {output}=require(a3_0x5c82('0x37'));class CloudRunApi{constructor(_0x69d93b,_0x2ead3a,_0x311b4f,_0x336bb2){this[a3_0x5c82('0x26')]=_0x69d93b;this[a3_0x5c82('0x2c')]=_0x2ead3a;this['machineInfo']=_0x336bb2;this[a3_0x5c82('0x1c')]=(0x0,axios_1[a3_0x5c82('0xa')])(_0x311b4f);}[a3_0x5c82('0x42')](_0x246adc,_0x2d2a3b){var _0x4e4756;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x433f73=(0x0,metric_logger_1[a3_0x5c82('0x3e')])(a3_0x5c82('0x42'));try{const _0xe641b={'meta':{'nxCloudVersion':this['nxCloudVersion']()},'branch':(0x0,environment_1['getBranch'])(),'runGroup':(0x0,environment_1[a3_0x5c82('0x1b')])(),'distributedExecutionId':_0x246adc,'hashes':_0x2d2a3b};if(environment_1[a3_0x5c82('0xe')]){output['note']({'title':a3_0x5c82('0x3'),'bodyLines':['\x0a'+JSON[a3_0x5c82('0x43')](_0xe641b,null,0x2)]});}const _0x5ec641=yield(0x0,axios_1[a3_0x5c82('0x17')])(()=>this['apiAxiosInstance']['post'](a3_0x5c82('0x8'),_0xe641b));_0x433f73[a3_0x5c82('0x1a')]((0x0,metric_logger_1['mapRespToPerfEntry'])(_0x5ec641));if(_0x5ec641[a3_0x5c82('0x27')]&&_0x5ec641[a3_0x5c82('0x27')][a3_0x5c82('0xf')]){this['messages']['message']=_0x5ec641[a3_0x5c82('0x27')]['message'];}if(!_0x5ec641[a3_0x5c82('0x27')]||!_0x5ec641[a3_0x5c82('0x27')][a3_0x5c82('0x10')]){this[a3_0x5c82('0x26')]['apiError']='Invalid\x20Nx\x20Cloud\x20response:\x20'+JSON['stringify'](_0x5ec641['data']);return{};}return _0x5ec641['data'][a3_0x5c82('0x10')];}catch(_0x1bc3b8){_0x433f73['recordMetric'](((_0x4e4756=_0x1bc3b8===null||_0x1bc3b8===void 0x0?void 0x0:_0x1bc3b8[a3_0x5c82('0x1e')])===null||_0x4e4756===void 0x0?void 0x0:_0x4e4756['response'])?(0x0,metric_logger_1[a3_0x5c82('0x21')])(_0x1bc3b8[a3_0x5c82('0x1e')][a3_0x5c82('0x3b')]):metric_logger_1['RUNNER_FAILURE_PERF_ENTRY']);this['messages']['apiError']=this[a3_0x5c82('0x26')][a3_0x5c82('0x3d')](_0x1bc3b8,a3_0x5c82('0x0'));return{};}});}[a3_0x5c82('0x2')](_0x4af27b,_0x3b05ef){const _0x25b26d={'meta':{'nxCloudVersion':this[a3_0x5c82('0x13')]()},'tasks':_0x3b05ef,'run':_0x4af27b,'machineInfo':this[a3_0x5c82('0x2f')]};return JSON[a3_0x5c82('0x43')](_0x25b26d);}[a3_0x5c82('0x40')](_0x180faf,_0x29bbba){var _0xbb3e5c,_0x3f1115;return __awaiter(this,void 0x0,void 0x0,function*(){if(this[a3_0x5c82('0x26')][a3_0x5c82('0xd')])return![];let _0x2bacee=this['createReqBody'](_0x180faf,_0x29bbba);if(_0x2bacee[a3_0x5c82('0xb')]>0x14*0x3e8*0x3e8){_0x2bacee=this[a3_0x5c82('0x2')](_0x180faf,_0x29bbba[a3_0x5c82('0x2a')](_0x580bdf=>Object['assign'](Object[a3_0x5c82('0x44')]({},_0x580bdf),{'hashDetails':undefined})));}const _0x2a472c=Buffer['from'](_0x2bacee);const _0x137b5e=yield(0x0,util_1['promisify'])(zlib_1[a3_0x5c82('0x32')])(_0x2a472c);const _0x177820=(0x0,metric_logger_1[a3_0x5c82('0x3e')])(a3_0x5c82('0x40'));try{if(environment_1[a3_0x5c82('0xe')]){const _0x4c4c04=_0x29bbba[a3_0x5c82('0x2a')](_0x6bae88=>{return Object['assign'](Object['assign']({},_0x6bae88),{'terminalOutput':_0x6bae88[a3_0x5c82('0x35')]?_0x6bae88[a3_0x5c82('0x35')]['slice'](0x0,0x14)+'...':undefined});});output[a3_0x5c82('0x38')]({'title':a3_0x5c82('0x1d'),'bodyLines':['\x0a'+JSON[a3_0x5c82('0x43')](_0x4c4c04,null,0x2)]});}const _0x167707=yield(0x0,axios_1[a3_0x5c82('0x17')])(()=>this[a3_0x5c82('0x1c')][a3_0x5c82('0x2d')]('/nx-cloud/runs/end',_0x137b5e,{'headers':Object[a3_0x5c82('0x44')](Object[a3_0x5c82('0x44')]({},this['apiAxiosInstance'][a3_0x5c82('0x16')][a3_0x5c82('0x2e')]),{'Content-Encoding':a3_0x5c82('0x32'),'Content-Type':a3_0x5c82('0x22')})}));if(_0x167707){_0x177820[a3_0x5c82('0x1a')]((0x0,metric_logger_1[a3_0x5c82('0x21')])(_0x167707));if(_0x167707[a3_0x5c82('0x27')]&&_0x167707[a3_0x5c82('0x27')]['runUrl']&&_0x167707[a3_0x5c82('0x27')][a3_0x5c82('0x7')]===a3_0x5c82('0x5')){this[a3_0x5c82('0x2c')][a3_0x5c82('0x24')]=_0x167707['data'][a3_0x5c82('0x24')];return!![];}if(_0x167707['data']&&_0x167707['data'][a3_0x5c82('0x7')]){this[a3_0x5c82('0x26')][a3_0x5c82('0xd')]='Invalid\x20end\x20run\x20response:\x20'+JSON[a3_0x5c82('0x43')](_0x167707[a3_0x5c82('0x27')][a3_0x5c82('0xf')]);}else if(_0x167707[a3_0x5c82('0x27')]&&typeof _0x167707['data']===a3_0x5c82('0x45')){if(_0x167707['data']!=='success'){this[a3_0x5c82('0x26')][a3_0x5c82('0xd')]=a3_0x5c82('0x18')+JSON[a3_0x5c82('0x43')](_0x167707[a3_0x5c82('0x27')]);}}else{this[a3_0x5c82('0x26')][a3_0x5c82('0xd')]=a3_0x5c82('0x18')+JSON[a3_0x5c82('0x43')](_0x167707[a3_0x5c82('0x27')]);}if(environment_1['VERBOSE_LOGGING']){output[a3_0x5c82('0x38')]({'title':a3_0x5c82('0x14'),'bodyLines':[JSON[a3_0x5c82('0x43')](_0x167707[a3_0x5c82('0x27')],null,0x2)]});}}else{output[a3_0x5c82('0x31')]({'title':a3_0x5c82('0x1'),'bodyLines':[a3_0x5c82('0x15'),a3_0x5c82('0x36'),JSON[a3_0x5c82('0x43')](_0x180faf,null,0x2),a3_0x5c82('0x1f'),JSON['stringify'](new Error()[a3_0x5c82('0x28')],null,0x2)]});}return![];}catch(_0xa98199){_0x177820[a3_0x5c82('0x1a')](((_0xbb3e5c=_0xa98199===null||_0xa98199===void 0x0?void 0x0:_0xa98199[a3_0x5c82('0x1e')])===null||_0xbb3e5c===void 0x0?void 0x0:_0xbb3e5c[a3_0x5c82('0x3b')])?(0x0,metric_logger_1['mapRespToPerfEntry'])(_0xa98199[a3_0x5c82('0x1e')][a3_0x5c82('0x3b')]):metric_logger_1[a3_0x5c82('0x29')]);const _0x30b4ab=(_0x3f1115=_0xa98199['axiosException'])!==null&&_0x3f1115!==void 0x0?_0x3f1115:_0xa98199;this[a3_0x5c82('0x26')][a3_0x5c82('0xd')]=this[a3_0x5c82('0x26')][a3_0x5c82('0x3d')](_0x30b4ab,a3_0x5c82('0x0'));return![];}});}[a3_0x5c82('0x13')](){try{const _0x3c9e4d=JSON[a3_0x5c82('0x20')]((0x0,fs_1['readFileSync'])(a3_0x5c82('0x3c'))[a3_0x5c82('0x25')]());return _0x3c9e4d[a3_0x5c82('0x39')][a3_0x5c82('0x34')];}catch(_0x49c661){return a3_0x5c82('0x6');}}}exports[a3_0x5c82('0x3f')]=CloudRunApi;
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
+ 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 +1,79 @@
1
- const a4_0x2fa3=['DistributedAgentApi','../../../utilities/environment','completeRunGroup','done','__esModule','Completing\x20run\x20group\x20with\x20an\x20error','runGroup','../../../utilities/axios','throw','error','note','/nx-cloud/executions/complete-run-group','value','axiosMultipleTries','response','error:\x20','apiAxiosInstance','data','createMetricRecorder','RUNNER_FAILURE_PERF_ENTRY','tasks','next','defineProperty','dtePollTasks','createApiAxiosInstance','../../../utilities/metric-logger','completeRunGroupWithError','axiosException','post','agentName','apply','/nx-cloud/executions/tasks','then','recordMetric','mapRespToPerfEntry','../../../utilities/nx-imports'];(function(_0x1eab28,_0x2fa317){const _0x1c92e4=function(_0x51c13e){while(--_0x51c13e){_0x1eab28['push'](_0x1eab28['shift']());}};_0x1c92e4(++_0x2fa317);}(a4_0x2fa3,0xe4));const a4_0x1c92=function(_0x1eab28,_0x2fa317){_0x1eab28=_0x1eab28-0x0;let _0x1c92e4=a4_0x2fa3[_0x1eab28];return _0x1c92e4;};'use strict';var __awaiter=this&&this['__awaiter']||function(_0x5b0497,_0x129843,_0x136bf3,_0x34968b){function _0x302455(_0x27dfd1){return _0x27dfd1 instanceof _0x136bf3?_0x27dfd1:new _0x136bf3(function(_0x218068){_0x218068(_0x27dfd1);});}return new(_0x136bf3||(_0x136bf3=Promise))(function(_0x2616af,_0x2adc0a){function _0x216923(_0x5d6211){try{_0x3bbcf2(_0x34968b[a4_0x1c92('0x9')](_0x5d6211));}catch(_0x100e6c){_0x2adc0a(_0x100e6c);}}function _0x578951(_0x532ba7){try{_0x3bbcf2(_0x34968b[a4_0x1c92('0x20')](_0x532ba7));}catch(_0x2d769b){_0x2adc0a(_0x2d769b);}}function _0x3bbcf2(_0x69c3c6){_0x69c3c6[a4_0x1c92('0x1b')]?_0x2616af(_0x69c3c6[a4_0x1c92('0x0')]):_0x302455(_0x69c3c6[a4_0x1c92('0x0')])[a4_0x1c92('0x14')](_0x216923,_0x578951);}_0x3bbcf2((_0x34968b=_0x34968b[a4_0x1c92('0x12')](_0x5b0497,_0x129843||[]))[a4_0x1c92('0x9')]());});};Object[a4_0x1c92('0xa')](exports,a4_0x1c92('0x1c'),{'value':!![]});exports['DistributedAgentApi']=void 0x0;const axios_1=require(a4_0x1c92('0x1f'));const environment_1=require(a4_0x1c92('0x19'));const metric_logger_1=require(a4_0x1c92('0xd'));const {output}=require(a4_0x1c92('0x17'));class DistributedAgentApi{constructor(_0x28be98,_0x588059,_0x194ac3){this['runGroup']=_0x588059;this[a4_0x1c92('0x11')]=_0x194ac3;this['apiAxiosInstance']=(0x0,axios_1[a4_0x1c92('0xc')])(_0x28be98);}[a4_0x1c92('0x8')](_0x222f60,_0x1ef021,_0x3abbad){var _0xd8462a;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x2dc881=(0x0,metric_logger_1[a4_0x1c92('0x6')])(a4_0x1c92('0xb'));try{const _0x3d2ace=yield(0x0,axios_1[a4_0x1c92('0x1')])(()=>this[a4_0x1c92('0x4')][a4_0x1c92('0x10')](a4_0x1c92('0x13'),{'runGroup':this[a4_0x1c92('0x1e')],'agentName':this[a4_0x1c92('0x11')],'executionId':_0x222f60,'statusCode':_0x1ef021,'completedTasks':_0x3abbad}));_0x2dc881[a4_0x1c92('0x15')]((0x0,metric_logger_1[a4_0x1c92('0x16')])(_0x3d2ace));return _0x3d2ace[a4_0x1c92('0x5')];}catch(_0xd88ba){_0x2dc881[a4_0x1c92('0x15')](((_0xd8462a=_0xd88ba===null||_0xd88ba===void 0x0?void 0x0:_0xd88ba['axiosException'])===null||_0xd8462a===void 0x0?void 0x0:_0xd8462a['response'])?(0x0,metric_logger_1[a4_0x1c92('0x16')])(_0xd88ba['axiosException']['response']):metric_logger_1['RUNNER_FAILURE_PERF_ENTRY']);throw _0xd88ba;}});}[a4_0x1c92('0xe')](_0xf16c62){var _0x13926b;return __awaiter(this,void 0x0,void 0x0,function*(){if(environment_1['VERBOSE_LOGGING']){output[a4_0x1c92('0x22')]({'title':a4_0x1c92('0x1d'),'bodyLines':['runGroup:\x20'+this[a4_0x1c92('0x1e')],a4_0x1c92('0x3')+_0xf16c62]});}const _0x144a32=(0x0,metric_logger_1[a4_0x1c92('0x6')])(a4_0x1c92('0x1a'));try{const _0x33c7ba=yield(0x0,axios_1[a4_0x1c92('0x1')])(()=>this['apiAxiosInstance'][a4_0x1c92('0x10')](a4_0x1c92('0x23'),{'runGroup':this[a4_0x1c92('0x1e')],'agentName':this[a4_0x1c92('0x11')],'criticalErrorMessage':_0xf16c62}));if(environment_1['VERBOSE_LOGGING']){output[a4_0x1c92('0x22')]({'title':'Completed\x20run\x20group\x20with\x20an\x20error'});}_0x144a32['recordMetric']((0x0,metric_logger_1['mapRespToPerfEntry'])(_0x33c7ba));}catch(_0x1fc2ed){_0x144a32['recordMetric'](((_0x13926b=_0x1fc2ed===null||_0x1fc2ed===void 0x0?void 0x0:_0x1fc2ed[a4_0x1c92('0xf')])===null||_0x13926b===void 0x0?void 0x0:_0x13926b[a4_0x1c92('0x2')])?(0x0,metric_logger_1[a4_0x1c92('0x16')])(_0x1fc2ed[a4_0x1c92('0xf')]['response']):metric_logger_1[a4_0x1c92('0x7')]);console[a4_0x1c92('0x21')](_0x1fc2ed);}});}}exports[a4_0x1c92('0x18')]=DistributedAgentApi;
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) {
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