@nrwl/nx-cloud 15.0.2 → 15.1.0-beta0

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_0x474f=['waitForStoreRequestsToComplete','storage','runContext','next','api','__esModule','Nx\x20Cloud:\x20Cache\x20miss\x20','apply','fileStorage','all','note','hashUrls','scheduledTasks','then','filter','cacheError','store','extractErrorMessage','NX_CLOUD_DISTRIBUTED_EXECUTION_ID','.\x20Read\x20only\x20token\x20is\x20used.','reduce','messages','status','get','statuses','put','storeRequests','resolve','requests','.\x20Status\x20404.','VERBOSE_LOGGING','axiosException','done','response','push','cache-miss','map','defineProperty','hash','remote-cache-hit','value','../../../utilities/environment','startRun'];(function(_0x4527dd,_0x474f62){const _0x49c26a=function(_0x57b03d){while(--_0x57b03d){_0x4527dd['push'](_0x4527dd['shift']());}};_0x49c26a(++_0x474f62);}(a2_0x474f,0x186));const a2_0x49c2=function(_0x4527dd,_0x474f62){_0x4527dd=_0x4527dd-0x0;let _0x49c26a=a2_0x474f[_0x4527dd];return _0x49c26a;};'use strict';var __awaiter=this&&this['__awaiter']||function(_0x460e53,_0x2705aa,_0x23c62e,_0x53c5df){function _0x3c3818(_0x770cf4){return _0x770cf4 instanceof _0x23c62e?_0x770cf4:new _0x23c62e(function(_0x3e42ab){_0x3e42ab(_0x770cf4);});}return new(_0x23c62e||(_0x23c62e=Promise))(function(_0x52704b,_0x262fbd){function _0x3aee18(_0x2ce4f4){try{_0x5d6062(_0x53c5df[a2_0x49c2('0x0')](_0x2ce4f4));}catch(_0x5ad799){_0x262fbd(_0x5ad799);}}function _0x5cbac6(_0x1693b8){try{_0x5d6062(_0x53c5df['throw'](_0x1693b8));}catch(_0x20ff2d){_0x262fbd(_0x20ff2d);}}function _0x5d6062(_0x475fe8){_0x475fe8[a2_0x49c2('0x1d')]?_0x52704b(_0x475fe8[a2_0x49c2('0x25')]):_0x3c3818(_0x475fe8[a2_0x49c2('0x25')])[a2_0x49c2('0xa')](_0x3aee18,_0x5cbac6);}_0x5d6062((_0x53c5df=_0x53c5df[a2_0x49c2('0x4')](_0x460e53,_0x2705aa||[]))[a2_0x49c2('0x0')]());});};Object[a2_0x49c2('0x22')](exports,a2_0x49c2('0x2'),{'value':!![]});exports['CloudRemoteCache']=void 0x0;const environment_1=require(a2_0x49c2('0x26'));const {output}=require('../../../utilities/nx-imports');class CloudRemoteCache{constructor(_0x2ba945,_0x491d9f,_0x4bbde3,_0x1aab89){this[a2_0x49c2('0x12')]=_0x2ba945;this[a2_0x49c2('0x1')]=_0x491d9f;this[a2_0x49c2('0x2a')]=_0x4bbde3;this[a2_0x49c2('0x5')]=_0x1aab89;this[a2_0x49c2('0x17')]=[];}['retrieve'](_0x5a48df,_0x567ab8){var _0xf0a39b;return __awaiter(this,void 0x0,void 0x0,function*(){if(this[a2_0x49c2('0x12')]['cacheError'])return![];const _0x1bdaa6=yield this[a2_0x49c2('0x8')](_0x5a48df);if(!_0x1bdaa6||!_0x1bdaa6[a2_0x49c2('0x14')]){if(environment_1[a2_0x49c2('0x1b')]){output[a2_0x49c2('0x7')]({'title':a2_0x49c2('0x3')+_0x5a48df+'.'});}this[a2_0x49c2('0x2a')][a2_0x49c2('0x15')][_0x5a48df]=a2_0x49c2('0x20');return![];}try{yield this[a2_0x49c2('0x5')]['retrieve'](_0x5a48df,_0x1bdaa6['get'],_0x567ab8);this['runContext']['statuses'][_0x5a48df]=a2_0x49c2('0x24');return!![];}catch(_0x1c1495){const _0x11ce9c=(_0xf0a39b=_0x1c1495[a2_0x49c2('0x1c')])!==null&&_0xf0a39b!==void 0x0?_0xf0a39b:_0x1c1495;if(_0x11ce9c[a2_0x49c2('0x1e')]&&_0x11ce9c[a2_0x49c2('0x1e')][a2_0x49c2('0x13')]===0x194){if(environment_1[a2_0x49c2('0x1b')]){output[a2_0x49c2('0x7')]({'title':'Nx\x20Cloud:\x20Cache\x20miss\x20'+_0x5a48df+a2_0x49c2('0x1a')});}}else{this[a2_0x49c2('0x12')][a2_0x49c2('0xc')]=this[a2_0x49c2('0x12')][a2_0x49c2('0xe')](_0x11ce9c,a2_0x49c2('0x29'));}this['runContext'][a2_0x49c2('0x15')][_0x5a48df]=a2_0x49c2('0x20');return![];}});}[a2_0x49c2('0xd')](_0x5464fb,_0x158f12){return __awaiter(this,void 0x0,void 0x0,function*(){if(this[a2_0x49c2('0x12')][a2_0x49c2('0xc')])return![];const _0x5ee611=Promise[a2_0x49c2('0x18')]()['then'](()=>__awaiter(this,void 0x0,void 0x0,function*(){var _0x1991fc;const _0x183782=yield this[a2_0x49c2('0x8')](_0x5464fb);if(!_0x183782)return![];if(!_0x183782[a2_0x49c2('0x16')]){if(environment_1[a2_0x49c2('0x1b')]){output[a2_0x49c2('0x7')]({'title':'Nx\x20Cloud:\x20Skipping\x20storing\x20'+_0x5464fb+a2_0x49c2('0x10')});}return!![];}try{yield this[a2_0x49c2('0x5')][a2_0x49c2('0xd')](_0x5464fb,_0x183782['put'],_0x158f12);return!![];}catch(_0x45fd09){const _0x10db86=(_0x1991fc=_0x45fd09[a2_0x49c2('0x1c')])!==null&&_0x1991fc!==void 0x0?_0x1991fc:_0x45fd09;this['messages']['cacheError']=this[a2_0x49c2('0x12')][a2_0x49c2('0xe')](_0x10db86,'storage');return![];}}));this['storeRequests']['push'](_0x5ee611);return _0x5ee611;});}[a2_0x49c2('0x8')](_0x8a3fc0){return __awaiter(this,void 0x0,void 0x0,function*(){if(_0x8a3fc0 in this['runContext'][a2_0x49c2('0x19')]){return(yield this[a2_0x49c2('0x2a')]['requests'][_0x8a3fc0])[_0x8a3fc0];}else{const _0x118518=this[a2_0x49c2('0x2a')][a2_0x49c2('0x9')][a2_0x49c2('0xb')](_0x1760c5=>!this[a2_0x49c2('0x2a')][a2_0x49c2('0x19')][_0x1760c5[a2_0x49c2('0x23')]])[a2_0x49c2('0x21')](_0x1e1119=>_0x1e1119[a2_0x49c2('0x23')]);if(_0x118518['indexOf'](_0x8a3fc0)===-0x1){_0x118518[a2_0x49c2('0x1f')](_0x8a3fc0);}const _0xa7e663=this[a2_0x49c2('0x1')][a2_0x49c2('0x27')](environment_1[a2_0x49c2('0xf')],_0x118518);_0x118518['forEach'](_0x55c802=>{this[a2_0x49c2('0x2a')][a2_0x49c2('0x19')][_0x55c802]=_0xa7e663;});return(yield _0xa7e663)[_0x8a3fc0];}});}[a2_0x49c2('0x28')](){return Promise[a2_0x49c2('0x6')](this['storeRequests'])[a2_0x49c2('0xa')](_0x3c99d4=>_0x3c99d4[a2_0x49c2('0x11')]((_0x54b843,_0x454b81)=>_0x54b843&&_0x454b81,!![]));}}exports['CloudRemoteCache']=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,167 @@
1
- const a3_0x5043=['axiosException','../../../utilities/environment','status','__esModule','../../../utilities/metric-logger','from','Run\x20completion\x20responded\x20with\x20`undefined`.','util','Run\x20Details:','headers','RUNNER_FAILURE_PERF_ENTRY','runUrl','CloudRunApi','__awaiter','note','map','post','devDependencies','getBranch','terminalOutput','/nx-cloud/runs/start','endRun','Nx\x20Cloud:\x20Unknown\x20Error\x20Occurred','nxCloudVersion','gzip','response','machineInfo','toString','createMetricRecorder','../../../utilities/axios','application/octet-stream','VERBOSE_LOGGING','startRun','next','messages','@nrwl/nx-cloud','Invalid\x20end\x20run\x20response:\x20','extractErrorMessage','slice','apiError','apiAxiosInstance','data','readFileSync','then','RunEnd.\x20Completed\x20tasks','message','throw','promisify','runContext','../../../utilities/nx-imports','stringify','unknown','axiosMultipleTries','Invalid\x20Nx\x20Cloud\x20response:\x20','RunEnd\x20duration','done','createReqBody','urls','/nx-cloud/runs/end','length','recordMetric','mapRespToPerfEntry','assign'];(function(_0x60cfcb,_0x504341){const _0x212e50=function(_0x58d772){while(--_0x58d772){_0x60cfcb['push'](_0x60cfcb['shift']());}};_0x212e50(++_0x504341);}(a3_0x5043,0x7d));const a3_0x212e=function(_0x60cfcb,_0x504341){_0x60cfcb=_0x60cfcb-0x0;let _0x212e50=a3_0x5043[_0x60cfcb];return _0x212e50;};'use strict';var __awaiter=this&&this[a3_0x212e('0xe')]||function(_0x5ddd12,_0x4d8fc2,_0x292a70,_0x37ac42){function _0x264307(_0x4d39c6){return _0x4d39c6 instanceof _0x292a70?_0x4d39c6:new _0x292a70(function(_0x2baaa2){_0x2baaa2(_0x4d39c6);});}return new(_0x292a70||(_0x292a70=Promise))(function(_0x1d483c,_0x23a032){function _0x1ab98b(_0x1394c9){try{_0x16be5f(_0x37ac42['next'](_0x1394c9));}catch(_0x862e48){_0x23a032(_0x862e48);}}function _0x1fe5c4(_0xbe122f){try{_0x16be5f(_0x37ac42[a3_0x212e('0x2f')](_0xbe122f));}catch(_0x254b7f){_0x23a032(_0x254b7f);}}function _0x16be5f(_0x1dc1de){_0x1dc1de[a3_0x212e('0x38')]?_0x1d483c(_0x1dc1de['value']):_0x264307(_0x1dc1de['value'])[a3_0x212e('0x2c')](_0x1ab98b,_0x1fe5c4);}_0x16be5f((_0x37ac42=_0x37ac42['apply'](_0x5ddd12,_0x4d8fc2||[]))[a3_0x212e('0x22')]());});};Object['defineProperty'](exports,a3_0x212e('0x4'),{'value':!![]});exports[a3_0x212e('0xd')]=void 0x0;const axios_1=require(a3_0x212e('0x1e'));const environment_1=require(a3_0x212e('0x2'));const fs_1=require('fs');const zlib_1=require('zlib');const util_1=require(a3_0x212e('0x8'));const metric_logger_1=require(a3_0x212e('0x5'));const {output}=require(a3_0x212e('0x32'));class CloudRunApi{constructor(_0x4b2b60,_0x374319,_0x578256,_0x48ebfa){this[a3_0x212e('0x23')]=_0x4b2b60;this[a3_0x212e('0x31')]=_0x374319;this[a3_0x212e('0x1b')]=_0x48ebfa;this[a3_0x212e('0x29')]=(0x0,axios_1['createApiAxiosInstance'])(_0x578256);}[a3_0x212e('0x21')](_0x2f5114,_0x476cbc){var _0x39b5c9;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x543469=(0x0,metric_logger_1[a3_0x212e('0x1d')])(a3_0x212e('0x21'));try{const _0x568b53={'meta':{'nxCloudVersion':this['nxCloudVersion']()},'branch':(0x0,environment_1[a3_0x212e('0x13')])(),'runGroup':(0x0,environment_1['getRunGroup'])(),'distributedExecutionId':_0x2f5114,'hashes':_0x476cbc};if(environment_1[a3_0x212e('0x20')]){output['note']({'title':'RunStart','bodyLines':['\x0a'+JSON[a3_0x212e('0x33')](_0x568b53,null,0x2)]});}const _0x2c550d=yield(0x0,axios_1['printDuration'])('RunStart\x20duration',()=>(0x0,axios_1['axiosMultipleTries'])(()=>this[a3_0x212e('0x29')][a3_0x212e('0x11')](a3_0x212e('0x15'),_0x568b53)));_0x543469['recordMetric']((0x0,metric_logger_1[a3_0x212e('0x3e')])(_0x2c550d));if(_0x2c550d[a3_0x212e('0x2a')]&&_0x2c550d['data'][a3_0x212e('0x2e')]){this['messages'][a3_0x212e('0x2e')]=_0x2c550d['data'][a3_0x212e('0x2e')];}if(!_0x2c550d[a3_0x212e('0x2a')]||!_0x2c550d[a3_0x212e('0x2a')][a3_0x212e('0x3a')]){this['messages']['apiError']=a3_0x212e('0x36')+JSON[a3_0x212e('0x33')](_0x2c550d[a3_0x212e('0x2a')]);return{};}return _0x2c550d[a3_0x212e('0x2a')][a3_0x212e('0x3a')];}catch(_0x430093){_0x543469[a3_0x212e('0x3d')](((_0x39b5c9=_0x430093===null||_0x430093===void 0x0?void 0x0:_0x430093[a3_0x212e('0x1')])===null||_0x39b5c9===void 0x0?void 0x0:_0x39b5c9[a3_0x212e('0x1a')])?(0x0,metric_logger_1[a3_0x212e('0x3e')])(_0x430093[a3_0x212e('0x1')][a3_0x212e('0x1a')]):metric_logger_1[a3_0x212e('0xb')]);this['messages'][a3_0x212e('0x28')]=this[a3_0x212e('0x23')][a3_0x212e('0x26')](_0x430093,'api');return{};}});}[a3_0x212e('0x39')](_0x112e99,_0x1ac126,_0x248a2b){const _0xb003a2={'meta':{'nxCloudVersion':this[a3_0x212e('0x18')]()},'tasks':_0x1ac126,'run':_0x112e99,'linkId':_0x248a2b,'machineInfo':this[a3_0x212e('0x1b')]};return JSON['stringify'](_0xb003a2);}['endRun'](_0x369594,_0x4c6d16,_0x55a6f6){var _0x1af2c0,_0x24c17a;return __awaiter(this,void 0x0,void 0x0,function*(){if(this[a3_0x212e('0x23')][a3_0x212e('0x28')])return![];let _0x567158=this[a3_0x212e('0x39')](_0x369594,_0x4c6d16,_0x55a6f6);if(_0x567158[a3_0x212e('0x3c')]>0x14*0x3e8*0x3e8){_0x567158=this[a3_0x212e('0x39')](_0x369594,_0x4c6d16[a3_0x212e('0x10')](_0x334485=>Object[a3_0x212e('0x0')](Object[a3_0x212e('0x0')]({},_0x334485),{'hashDetails':undefined})));}const _0x228875=Buffer[a3_0x212e('0x6')](_0x567158);const _0x2e2f2a=yield(0x0,util_1[a3_0x212e('0x30')])(zlib_1['gzip'])(_0x228875);const _0x1b83b9=(0x0,metric_logger_1[a3_0x212e('0x1d')])(a3_0x212e('0x16'));try{if(environment_1[a3_0x212e('0x20')]){const _0x1949f9=_0x4c6d16[a3_0x212e('0x10')](_0x17eaaa=>{return Object[a3_0x212e('0x0')](Object['assign']({},_0x17eaaa),{'terminalOutput':_0x17eaaa[a3_0x212e('0x14')]?_0x17eaaa[a3_0x212e('0x14')][a3_0x212e('0x27')](0x0,0x14)+'...':undefined});});output[a3_0x212e('0xf')]({'title':a3_0x212e('0x2d'),'bodyLines':['\x0a'+JSON['stringify'](_0x1949f9,null,0x2)]});}const _0x40b49f=yield(0x0,axios_1['printDuration'])(a3_0x212e('0x37'),()=>(0x0,axios_1[a3_0x212e('0x35')])(()=>this[a3_0x212e('0x29')][a3_0x212e('0x11')](a3_0x212e('0x3b'),_0x2e2f2a,{'headers':Object[a3_0x212e('0x0')](Object[a3_0x212e('0x0')]({},this[a3_0x212e('0x29')]['defaults'][a3_0x212e('0xa')]),{'Content-Encoding':a3_0x212e('0x19'),'Content-Type':a3_0x212e('0x1f')})})));if(_0x40b49f){_0x1b83b9[a3_0x212e('0x3d')]((0x0,metric_logger_1[a3_0x212e('0x3e')])(_0x40b49f));if(_0x40b49f['data']&&_0x40b49f[a3_0x212e('0x2a')][a3_0x212e('0xc')]&&_0x40b49f['data']['status']==='success'){this[a3_0x212e('0x31')][a3_0x212e('0xc')]=_0x40b49f[a3_0x212e('0x2a')][a3_0x212e('0xc')];return!![];}if(_0x40b49f['data']&&_0x40b49f[a3_0x212e('0x2a')][a3_0x212e('0x3')]){this[a3_0x212e('0x23')][a3_0x212e('0x28')]=a3_0x212e('0x25')+JSON[a3_0x212e('0x33')](_0x40b49f[a3_0x212e('0x2a')][a3_0x212e('0x2e')]);}else if(_0x40b49f[a3_0x212e('0x2a')]&&typeof _0x40b49f[a3_0x212e('0x2a')]==='string'){if(_0x40b49f[a3_0x212e('0x2a')]!=='success'){this[a3_0x212e('0x23')][a3_0x212e('0x28')]='Invalid\x20end\x20run\x20response:\x20'+JSON[a3_0x212e('0x33')](_0x40b49f['data']);}}else{this['messages'][a3_0x212e('0x28')]=a3_0x212e('0x25')+JSON['stringify'](_0x40b49f[a3_0x212e('0x2a')]);}if(environment_1[a3_0x212e('0x20')]){output[a3_0x212e('0xf')]({'title':'Invalid\x20end\x20run\x20response','bodyLines':[JSON['stringify'](_0x40b49f[a3_0x212e('0x2a')],null,0x2)]});}}else{output['error']({'title':a3_0x212e('0x17'),'bodyLines':[a3_0x212e('0x7'),a3_0x212e('0x9'),JSON[a3_0x212e('0x33')](_0x369594,null,0x2),'Stack\x20Trace:',JSON[a3_0x212e('0x33')](new Error()['stack'],null,0x2)]});}return![];}catch(_0x359d68){_0x1b83b9[a3_0x212e('0x3d')](((_0x1af2c0=_0x359d68===null||_0x359d68===void 0x0?void 0x0:_0x359d68['axiosException'])===null||_0x1af2c0===void 0x0?void 0x0:_0x1af2c0[a3_0x212e('0x1a')])?(0x0,metric_logger_1[a3_0x212e('0x3e')])(_0x359d68['axiosException']['response']):metric_logger_1['RUNNER_FAILURE_PERF_ENTRY']);const _0x3afbf7=(_0x24c17a=_0x359d68['axiosException'])!==null&&_0x24c17a!==void 0x0?_0x24c17a:_0x359d68;this[a3_0x212e('0x23')][a3_0x212e('0x28')]=this[a3_0x212e('0x23')][a3_0x212e('0x26')](_0x3afbf7,'api');return![];}});}[a3_0x212e('0x18')](){try{const _0x2c6a9c=JSON['parse']((0x0,fs_1[a3_0x212e('0x2b')])('package.json')[a3_0x212e('0x1c')]());return _0x2c6a9c[a3_0x212e('0x12')][a3_0x212e('0x24')];}catch(_0x107e04){return a3_0x212e('0x34');}}}exports[a3_0x212e('0xd')]=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.printDuration)('RunStart duration', () => (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, linkId) {
68
+ const uncompressedReqBody = {
69
+ meta: {
70
+ nxCloudVersion: this.nxCloudVersion(),
71
+ },
72
+ tasks,
73
+ run,
74
+ linkId,
75
+ machineInfo: this.machineInfo,
76
+ };
77
+ return JSON.stringify(uncompressedReqBody);
78
+ }
79
+ endRun(run, tasks, linkId) {
80
+ var _a, _b;
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ // API is not working, don't make the end request
83
+ if (this.messages.apiError)
84
+ return false;
85
+ let uncompressedBodyString = this.createReqBody(run, tasks, linkId);
86
+ // if the req body is > 20mb, remove hashDetails
87
+ if (uncompressedBodyString.length > 20 * 1000 * 1000) {
88
+ uncompressedBodyString = this.createReqBody(run, tasks.map((t) => (Object.assign(Object.assign({}, t), { hashDetails: undefined }))));
89
+ }
90
+ const uncompressedBuffer = Buffer.from(uncompressedBodyString);
91
+ const compressedBuffer = yield (0, util_1.promisify)(zlib_1.gzip)(uncompressedBuffer);
92
+ const recorder = (0, metric_logger_1.createMetricRecorder)('endRun');
93
+ try {
94
+ if (environment_1.VERBOSE_LOGGING) {
95
+ const t = tasks.map((tt) => {
96
+ return Object.assign(Object.assign({}, tt), { terminalOutput: tt.terminalOutput
97
+ ? `${tt.terminalOutput.slice(0, 20)}...`
98
+ : undefined });
99
+ });
100
+ output.note({
101
+ title: 'RunEnd. Completed tasks',
102
+ bodyLines: ['\n' + JSON.stringify(t, null, 2)],
103
+ });
104
+ }
105
+ const resp = yield (0, axios_1.printDuration)('RunEnd duration', () => (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/runs/end', compressedBuffer, {
106
+ headers: Object.assign(Object.assign({}, this.apiAxiosInstance.defaults.headers), { 'Content-Encoding': 'gzip', 'Content-Type': 'application/octet-stream' }),
107
+ })));
108
+ if (resp) {
109
+ recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
110
+ if (resp.data && resp.data.runUrl && resp.data.status === 'success') {
111
+ this.runContext.runUrl = resp.data.runUrl;
112
+ return true;
113
+ }
114
+ if (resp.data && resp.data.status) {
115
+ this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data.message)}`;
116
+ }
117
+ else if (resp.data && typeof resp.data === 'string') {
118
+ if (resp.data !== 'success') {
119
+ this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data)}`;
120
+ }
121
+ }
122
+ else {
123
+ this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data)}`;
124
+ }
125
+ if (environment_1.VERBOSE_LOGGING) {
126
+ output.note({
127
+ title: 'Invalid end run response',
128
+ bodyLines: [JSON.stringify(resp.data, null, 2)],
129
+ });
130
+ }
131
+ }
132
+ else {
133
+ output.error({
134
+ title: 'Nx Cloud: Unknown Error Occurred',
135
+ bodyLines: [
136
+ 'Run completion responded with `undefined`.',
137
+ 'Run Details:',
138
+ JSON.stringify(run, null, 2),
139
+ 'Stack Trace:',
140
+ JSON.stringify(new Error().stack, null, 2),
141
+ ],
142
+ });
143
+ }
144
+ return false;
145
+ }
146
+ catch (ee) {
147
+ recorder.recordMetric(((_a = ee === null || ee === void 0 ? void 0 : ee.axiosException) === null || _a === void 0 ? void 0 : _a.response)
148
+ ? (0, metric_logger_1.mapRespToPerfEntry)(ee.axiosException.response)
149
+ : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
150
+ const e = (_b = ee.axiosException) !== null && _b !== void 0 ? _b : ee;
151
+ this.messages.apiError = this.messages.extractErrorMessage(e, 'api');
152
+ return false;
153
+ }
154
+ });
155
+ }
156
+ nxCloudVersion() {
157
+ try {
158
+ const v = JSON.parse((0, fs_1.readFileSync)(`package.json`).toString());
159
+ return v.devDependencies['@nrwl/nx-cloud'];
160
+ }
161
+ catch (e) {
162
+ return 'unknown';
163
+ }
164
+ }
165
+ }
166
+ exports.CloudRunApi = CloudRunApi;
167
+ //# sourceMappingURL=cloud-run.api.js.map
@@ -1 +1,16 @@
1
- const a4_0x1daa=['length','ABCDEFGHIJKLMNOPQRSTUVWXYZ','defineProperty','0123456789','floor','generateUniqueLinkId','toLowerCase','random'];(function(_0x2fe2e2,_0x1daab0){const _0x419c2a=function(_0x1aa1b1){while(--_0x1aa1b1){_0x2fe2e2['push'](_0x2fe2e2['shift']());}};_0x419c2a(++_0x1daab0);}(a4_0x1daa,0x12d));const a4_0x419c=function(_0x2fe2e2,_0x1daab0){_0x2fe2e2=_0x2fe2e2-0x0;let _0x419c2a=a4_0x1daa[_0x2fe2e2];return _0x419c2a;};'use strict';Object[a4_0x419c('0x5')](exports,'__esModule',{'value':!![]});exports['generateUniqueLinkId']=void 0x0;const upper=a4_0x419c('0x4');const digits=a4_0x419c('0x6');const lower=upper[a4_0x419c('0x1')]();const alphanum=upper+lower+digits;function generateUniqueLinkId(){let _0x43166f='';for(let _0xa7fa6f=0x0;_0xa7fa6f<0xa;++_0xa7fa6f){_0x43166f+=alphanum[Math[a4_0x419c('0x7')](Math[a4_0x419c('0x2')]()*alphanum[a4_0x419c('0x3')])];}return _0x43166f;}exports[a4_0x419c('0x0')]=generateUniqueLinkId;
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 +1,79 @@
1
- const a5_0x4d4a=['DistributedAgentApi','recordMetric','agentName','Completed\x20run\x20group\x20with\x20an\x20error','mapRespToPerfEntry','/nx-cloud/executions/tasks','RUNNER_FAILURE_PERF_ENTRY','note','__esModule','__awaiter','createMetricRecorder','../../../utilities/nx-imports','throw','/nx-cloud/executions/complete-run-group','tasks','done','next','apply','runGroup:\x20','VERBOSE_LOGGING','../../../utilities/axios','response','value','createApiAxiosInstance','apiAxiosInstance','axiosException','completeRunGroup','../../../utilities/metric-logger','Completing\x20run\x20group\x20with\x20an\x20error','error','runGroup'];(function(_0x165e11,_0x4d4a14){const _0xbcb0bb=function(_0x420db5){while(--_0x420db5){_0x165e11['push'](_0x165e11['shift']());}};_0xbcb0bb(++_0x4d4a14);}(a5_0x4d4a,0xc2));const a5_0xbcb0=function(_0x165e11,_0x4d4a14){_0x165e11=_0x165e11-0x0;let _0xbcb0bb=a5_0x4d4a[_0x165e11];return _0xbcb0bb;};'use strict';var __awaiter=this&&this[a5_0xbcb0('0x1')]||function(_0x1d885b,_0x2db1ac,_0x35c639,_0x3584ba){function _0x3d25a9(_0x1091d7){return _0x1091d7 instanceof _0x35c639?_0x1091d7:new _0x35c639(function(_0x550c47){_0x550c47(_0x1091d7);});}return new(_0x35c639||(_0x35c639=Promise))(function(_0x1e12e2,_0x49bc8d){function _0x492c5c(_0xe21602){try{_0x208756(_0x3584ba['next'](_0xe21602));}catch(_0x4d80fa){_0x49bc8d(_0x4d80fa);}}function _0x5ad1ae(_0x3adf7e){try{_0x208756(_0x3584ba[a5_0xbcb0('0x4')](_0x3adf7e));}catch(_0xab29b5){_0x49bc8d(_0xab29b5);}}function _0x208756(_0x355978){_0x355978[a5_0xbcb0('0x7')]?_0x1e12e2(_0x355978['value']):_0x3d25a9(_0x355978[a5_0xbcb0('0xe')])['then'](_0x492c5c,_0x5ad1ae);}_0x208756((_0x3584ba=_0x3584ba[a5_0xbcb0('0x9')](_0x1d885b,_0x2db1ac||[]))[a5_0xbcb0('0x8')]());});};Object['defineProperty'](exports,a5_0xbcb0('0x0'),{'value':!![]});exports[a5_0xbcb0('0x17')]=void 0x0;const axios_1=require(a5_0xbcb0('0xc'));const environment_1=require('../../../utilities/environment');const metric_logger_1=require(a5_0xbcb0('0x13'));const {output}=require(a5_0xbcb0('0x3'));class DistributedAgentApi{constructor(_0x484ae6,_0x59a5fe,_0x4e4467){this['runGroup']=_0x59a5fe;this[a5_0xbcb0('0x19')]=_0x4e4467;this[a5_0xbcb0('0x10')]=(0x0,axios_1[a5_0xbcb0('0xf')])(_0x484ae6);}[a5_0xbcb0('0x6')](_0x1f5b3f,_0x9ab021,_0x11174f){var _0x4574ea;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x3657ed=(0x0,metric_logger_1[a5_0xbcb0('0x2')])('dtePollTasks');try{const _0x130e56=yield(0x0,axios_1['axiosMultipleTries'])(()=>this[a5_0xbcb0('0x10')]['post'](a5_0xbcb0('0x1c'),{'runGroup':this['runGroup'],'agentName':this[a5_0xbcb0('0x19')],'executionId':_0x1f5b3f,'statusCode':_0x9ab021,'completedTasks':_0x11174f}));_0x3657ed[a5_0xbcb0('0x18')]((0x0,metric_logger_1[a5_0xbcb0('0x1b')])(_0x130e56));return _0x130e56['data'];}catch(_0x4c7a16){_0x3657ed[a5_0xbcb0('0x18')](((_0x4574ea=_0x4c7a16===null||_0x4c7a16===void 0x0?void 0x0:_0x4c7a16[a5_0xbcb0('0x11')])===null||_0x4574ea===void 0x0?void 0x0:_0x4574ea[a5_0xbcb0('0xd')])?(0x0,metric_logger_1[a5_0xbcb0('0x1b')])(_0x4c7a16['axiosException']['response']):metric_logger_1[a5_0xbcb0('0x1d')]);throw _0x4c7a16;}});}['completeRunGroupWithError'](_0xffe6e3){var _0x2a1155;return __awaiter(this,void 0x0,void 0x0,function*(){if(environment_1[a5_0xbcb0('0xb')]){output[a5_0xbcb0('0x1e')]({'title':a5_0xbcb0('0x14'),'bodyLines':[a5_0xbcb0('0xa')+this[a5_0xbcb0('0x16')],'error:\x20'+_0xffe6e3]});}const _0x1de962=(0x0,metric_logger_1[a5_0xbcb0('0x2')])(a5_0xbcb0('0x12'));try{const _0x5293d7=yield(0x0,axios_1['axiosMultipleTries'])(()=>this[a5_0xbcb0('0x10')]['post'](a5_0xbcb0('0x5'),{'runGroup':this[a5_0xbcb0('0x16')],'agentName':this['agentName'],'criticalErrorMessage':_0xffe6e3}));if(environment_1[a5_0xbcb0('0xb')]){output[a5_0xbcb0('0x1e')]({'title':a5_0xbcb0('0x1a')});}_0x1de962['recordMetric']((0x0,metric_logger_1['mapRespToPerfEntry'])(_0x5293d7));}catch(_0x491916){_0x1de962[a5_0xbcb0('0x18')](((_0x2a1155=_0x491916===null||_0x491916===void 0x0?void 0x0:_0x491916[a5_0xbcb0('0x11')])===null||_0x2a1155===void 0x0?void 0x0:_0x2a1155[a5_0xbcb0('0xd')])?(0x0,metric_logger_1[a5_0xbcb0('0x1b')])(_0x491916[a5_0xbcb0('0x11')]['response']):metric_logger_1[a5_0xbcb0('0x1d')]);console[a5_0xbcb0('0x15')](_0x491916);}});}}exports['DistributedAgentApi']=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