@nrwl/nx-cloud 15.3.5 → 15.4.0-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.
Files changed (24) hide show
  1. package/lib/core/api/error-reporter.api.js +36 -1
  2. package/lib/core/api/run-group.api.js +73 -1
  3. package/lib/core/file-storage/file-storage.js +4 -2
  4. package/lib/core/file-storage/file-storage.js.map +1 -1
  5. package/lib/core/models/cloud-task-runner-options.d.ts +1 -1
  6. package/lib/core/runners/cloud-enabled/cloud-enabled-life-cycle.js +93 -1
  7. package/lib/core/runners/cloud-enabled/cloud-enabled.runner.js +320 -1
  8. package/lib/core/runners/cloud-enabled/cloud-remote-cache.js +133 -1
  9. package/lib/core/runners/cloud-enabled/cloud-run.api.js +174 -1
  10. package/lib/core/runners/cloud-enabled/id-generator.js +16 -1
  11. package/lib/core/runners/distributed-agent/distributed-agent.api.js +93 -1
  12. package/lib/core/runners/distributed-agent/distributed-agent.impl.js +157 -1
  13. package/lib/core/runners/distributed-agent/execute-tasks.js +114 -1
  14. package/lib/core/runners/distributed-agent/invoke-tasks-using-nx-imperative-api.js +58 -1
  15. package/lib/core/runners/distributed-agent/invoke-tasks-using-run-many.js +97 -1
  16. package/lib/core/runners/distributed-execution/distributed-execution.api.js +152 -1
  17. package/lib/core/runners/distributed-execution/distributed-execution.runner.js +118 -1
  18. package/lib/core/runners/distributed-execution/process-task.js +45 -1
  19. package/lib/core/runners/distributed-execution/process-tasks.js +67 -1
  20. package/lib/core/runners/distributed-execution/split-task-graph-into-stages.js +37 -1
  21. package/lib/core/runners/distributed-execution/task-graph-creator.js +100 -1
  22. package/lib/utilities/axios.js +8 -2
  23. package/lib/utilities/axios.js.map +1 -1
  24. package/package.json +1 -1
@@ -1 +1,133 @@
1
- const a2_0x4764=['reduce','scheduledTasks','store','map','resolve','.\x20Status\x20404.','all','__esModule','put','startRun','status','storeRequests','../../../utilities/environment','axiosException','messages','get','storage','then','Maybe\x20you\x20are\x20using\x20a\x20read-only\x20token\x20or\x20the\x20artifact\x20has\x20already\x20being\x20uploaded.','filter','forEach','runContext','hashUrls','apply','note','next','CloudRemoteCache','api','Error\x20when\x20storing\x20artifacts','response','delayedStoreRequests','distributedExecutionId','fileStorage','cacheError','requests','Nx\x20Cloud:\x20Skipping\x20storing\x20','push','extractErrorMessage','cache-miss','storeInCurrentProcess','hash','value','throw','Nx\x20Cloud:\x20Cache\x20miss\x20','remote-cache-hit','retrieve','statuses'];(function(_0x16c364,_0x476449){const _0x1f57d3=function(_0x5a762a){while(--_0x5a762a){_0x16c364['push'](_0x16c364['shift']());}};_0x1f57d3(++_0x476449);}(a2_0x4764,0xc3));const a2_0x1f57=function(_0x16c364,_0x476449){_0x16c364=_0x16c364-0x0;let _0x1f57d3=a2_0x4764[_0x16c364];return _0x1f57d3;};'use strict';var __awaiter=this&&this['__awaiter']||function(_0x1d82ec,_0x344044,_0x123259,_0x4c18b4){function _0x345e86(_0xf9f12e){return _0xf9f12e instanceof _0x123259?_0xf9f12e:new _0x123259(function(_0x513202){_0x513202(_0xf9f12e);});}return new(_0x123259||(_0x123259=Promise))(function(_0x3f13ae,_0x33ef92){function _0x105349(_0x1a6c51){try{_0x858f3(_0x4c18b4[a2_0x1f57('0x12')](_0x1a6c51));}catch(_0x4fd3cb){_0x33ef92(_0x4fd3cb);}}function _0x3cf2d3(_0x13b116){try{_0x858f3(_0x4c18b4[a2_0x1f57('0x23')](_0x13b116));}catch(_0x489627){_0x33ef92(_0x489627);}}function _0x858f3(_0x4404f0){_0x4404f0['done']?_0x3f13ae(_0x4404f0[a2_0x1f57('0x22')]):_0x345e86(_0x4404f0[a2_0x1f57('0x22')])[a2_0x1f57('0xa')](_0x105349,_0x3cf2d3);}_0x858f3((_0x4c18b4=_0x4c18b4[a2_0x1f57('0x10')](_0x1d82ec,_0x344044||[]))[a2_0x1f57('0x12')]());});};Object['defineProperty'](exports,a2_0x1f57('0x0'),{'value':!![]});exports[a2_0x1f57('0x13')]=void 0x0;const environment_1=require(a2_0x1f57('0x5'));const {output}=require('../../../utilities/nx-imports');class CloudRemoteCache{constructor(_0x3065c9,_0x1da5cb,_0x128c87,_0x357325,_0x56d357,_0xd0d498){this[a2_0x1f57('0x7')]=_0x3065c9;this[a2_0x1f57('0x14')]=_0x1da5cb;this[a2_0x1f57('0xe')]=_0x128c87;this[a2_0x1f57('0x19')]=_0x357325;this[a2_0x1f57('0x18')]=_0x56d357;this[a2_0x1f57('0x20')]=_0xd0d498;this[a2_0x1f57('0x4')]=[];this[a2_0x1f57('0x17')]=[];}[a2_0x1f57('0x26')](_0x23bb4b,_0xdedf42){var _0x2509d9;return __awaiter(this,void 0x0,void 0x0,function*(){if(this['messages'][a2_0x1f57('0x1a')])return![];const _0x1cbdd0=yield this['hashUrls'](_0x23bb4b);if(!_0x1cbdd0||!_0x1cbdd0[a2_0x1f57('0x8')]){if(environment_1['VERBOSE_LOGGING']){output[a2_0x1f57('0x11')]({'title':a2_0x1f57('0x24')+_0x23bb4b+'.'});}this['runContext']['statuses'][_0x23bb4b]=a2_0x1f57('0x1f');return![];}try{yield this[a2_0x1f57('0x19')][a2_0x1f57('0x26')](_0x23bb4b,_0x1cbdd0['get'],_0xdedf42);this['runContext'][a2_0x1f57('0x27')][_0x23bb4b]=a2_0x1f57('0x25');return!![];}catch(_0x205db8){const _0xf78372=(_0x2509d9=_0x205db8[a2_0x1f57('0x6')])!==null&&_0x2509d9!==void 0x0?_0x2509d9:_0x205db8;if(_0xf78372[a2_0x1f57('0x16')]&&_0xf78372[a2_0x1f57('0x16')][a2_0x1f57('0x3')]===0x194){if(environment_1['VERBOSE_LOGGING']){output[a2_0x1f57('0x11')]({'title':a2_0x1f57('0x24')+_0x23bb4b+a2_0x1f57('0x2d')});}}else{this[a2_0x1f57('0x7')][a2_0x1f57('0x1a')]=this[a2_0x1f57('0x7')][a2_0x1f57('0x1e')](_0xf78372,a2_0x1f57('0x9'));}this['runContext'][a2_0x1f57('0x27')][_0x23bb4b]=a2_0x1f57('0x1f');return![];}});}[a2_0x1f57('0x2a')](_0x23f9ee,_0x3a875f){return __awaiter(this,void 0x0,void 0x0,function*(){if(this[a2_0x1f57('0x7')][a2_0x1f57('0x1a')])return![];const _0x1d4f9c=Promise[a2_0x1f57('0x2c')]()[a2_0x1f57('0xa')](()=>__awaiter(this,void 0x0,void 0x0,function*(){var _0x110fd0;const _0x55c0fe=yield this['hashUrls'](_0x23f9ee);if(!_0x55c0fe)return![];if(!_0x55c0fe[a2_0x1f57('0x1')]){if(environment_1['VERBOSE_LOGGING']){output[a2_0x1f57('0x11')]({'title':a2_0x1f57('0x1c')+_0x23f9ee+'.','bodyLines':['There\x20are\x20several\x20reasons\x20why\x20this\x20can\x20happen.',a2_0x1f57('0xb')]});}return!![];}if(!this[a2_0x1f57('0x20')]){this['delayedStoreRequests']['push']({'hash':_0x23f9ee,'url':_0x55c0fe[a2_0x1f57('0x1')]});return!![];}try{yield this[a2_0x1f57('0x19')][a2_0x1f57('0x2a')](_0x23f9ee,_0x55c0fe[a2_0x1f57('0x1')],_0x3a875f);return!![];}catch(_0x366ee0){const _0x185a89=(_0x110fd0=_0x366ee0[a2_0x1f57('0x6')])!==null&&_0x110fd0!==void 0x0?_0x110fd0:_0x366ee0;this[a2_0x1f57('0x7')]['cacheError']=this[a2_0x1f57('0x7')][a2_0x1f57('0x1e')](_0x185a89,a2_0x1f57('0x9'));return![];}}));this[a2_0x1f57('0x4')]['push'](_0x1d4f9c);return _0x1d4f9c;});}[a2_0x1f57('0xf')](_0x1a8875){return __awaiter(this,void 0x0,void 0x0,function*(){if(_0x1a8875 in this[a2_0x1f57('0xe')][a2_0x1f57('0x1b')]){return(yield this[a2_0x1f57('0xe')][a2_0x1f57('0x1b')][_0x1a8875])[_0x1a8875];}else{const _0x48b5fa=this[a2_0x1f57('0xe')][a2_0x1f57('0x29')][a2_0x1f57('0xc')](_0x4a8762=>!this[a2_0x1f57('0xe')][a2_0x1f57('0x1b')][_0x4a8762[a2_0x1f57('0x21')]])[a2_0x1f57('0x2b')](_0x471fdd=>_0x471fdd[a2_0x1f57('0x21')]);if(_0x48b5fa['indexOf'](_0x1a8875)===-0x1){_0x48b5fa[a2_0x1f57('0x1d')](_0x1a8875);}const _0x5d627e=this[a2_0x1f57('0x14')][a2_0x1f57('0x2')](this[a2_0x1f57('0x18')],_0x48b5fa);_0x48b5fa[a2_0x1f57('0xd')](_0x370721=>{this[a2_0x1f57('0xe')][a2_0x1f57('0x1b')][_0x370721]=_0x5d627e;});return(yield _0x5d627e)[_0x1a8875];}});}['waitForStoreRequestsToComplete'](){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x39a3f=yield Promise[a2_0x1f57('0x2e')](this[a2_0x1f57('0x4')])[a2_0x1f57('0xa')](_0x1b538a=>_0x1b538a[a2_0x1f57('0x28')]((_0x512c54,_0x4582e4)=>_0x512c54&&_0x4582e4,!![]));if(!_0x39a3f){throw new Error(a2_0x1f57('0x15'));}});}}exports[a2_0x1f57('0x13')]=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, 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 +1,174 @@
1
- const a3_0x4ac4=['...','Invalid\x20end\x20run\x20response','__awaiter','stack','map','application/octet-stream','getBranch','RunStart','../../../utilities/nx-imports','uploadedToStorage','createMetricRecorder','apiError','length','Invalid\x20Nx\x20Cloud\x20response:\x20','../../../utilities/is-private-cloud','status','promisify','Nx\x20Cloud:\x20Unknown\x20Error\x20Occurred','string','nxCloudVersion','recordMetric','../../../utilities/axios','Run\x20completion\x20responded\x20with\x20`undefined`.','extractErrorMessage','terminalOutput','__esModule','assign','createReqBody','defineProperty','next','Run\x20Details:','mapRespToPerfEntry','urls','from','createApiAxiosInstance','success','value','messages','runContext','../../../utilities/metric-logger','isConnectedToPrivateCloud','defaults','unknown','parse','CloudRunApi','apply','response','post','then','note','readFileSync','message','data','../../../utilities/environment','runUrl','stringify','devDependencies','axiosException','error','Invalid\x20end\x20run\x20response:\x20','toString','endRun','gzip','startRun','RUNNER_FAILURE_PERF_ENTRY','headers','slice','machineInfo','getCIExecutionEnv','api','printDuration','apiAxiosInstance'];(function(_0x385f8c,_0x4ac416){const _0xd72646=function(_0x14c4a9){while(--_0x14c4a9){_0x385f8c['push'](_0x385f8c['shift']());}};_0xd72646(++_0x4ac416);}(a3_0x4ac4,0x151));const a3_0xd726=function(_0x385f8c,_0x4ac416){_0x385f8c=_0x385f8c-0x0;let _0xd72646=a3_0x4ac4[_0x385f8c];return _0xd72646;};'use strict';var __awaiter=this&&this[a3_0xd726('0x19')]||function(_0x1ab683,_0x2da259,_0x333853,_0x5a7f5b){function _0xd18f00(_0x497ede){return _0x497ede instanceof _0x333853?_0x497ede:new _0x333853(function(_0x4505dc){_0x4505dc(_0x497ede);});}return new(_0x333853||(_0x333853=Promise))(function(_0x2105c6,_0x2bd971){function _0x136f04(_0x4a1f94){try{_0x2e5e95(_0x5a7f5b[a3_0xd726('0x34')](_0x4a1f94));}catch(_0x1fbbf1){_0x2bd971(_0x1fbbf1);}}function _0x2e0f59(_0x2a908d){try{_0x2e5e95(_0x5a7f5b['throw'](_0x2a908d));}catch(_0x5e177d){_0x2bd971(_0x5e177d);}}function _0x2e5e95(_0x1818c7){_0x1818c7['done']?_0x2105c6(_0x1818c7[a3_0xd726('0x3b')]):_0xd18f00(_0x1818c7['value'])[a3_0xd726('0x47')](_0x136f04,_0x2e0f59);}_0x2e5e95((_0x5a7f5b=_0x5a7f5b[a3_0xd726('0x44')](_0x1ab683,_0x2da259||[]))['next']());});};Object[a3_0xd726('0x33')](exports,a3_0xd726('0x30'),{'value':!![]});exports[a3_0xd726('0x43')]=void 0x0;const axios_1=require(a3_0xd726('0x2c'));const environment_1=require(a3_0xd726('0x4'));const fs_1=require('fs');const zlib_1=require('zlib');const util_1=require('util');const metric_logger_1=require(a3_0xd726('0x3e'));const is_private_cloud_1=require(a3_0xd726('0x25'));const {output}=require(a3_0xd726('0x1f'));class CloudRunApi{constructor(_0x55c9ee,_0x5d0765,_0x3b4f32,_0x212171){this[a3_0xd726('0x3c')]=_0x55c9ee;this[a3_0xd726('0x3d')]=_0x5d0765;this[a3_0xd726('0x12')]=_0x212171;this[a3_0xd726('0x16')]=(0x0,axios_1[a3_0xd726('0x39')])(_0x3b4f32);}[a3_0xd726('0xe')](_0x24b5cd,_0x436af0){var _0x18881b;return __awaiter(this,void 0x0,void 0x0,function*(){if(this[a3_0xd726('0x3c')][a3_0xd726('0x22')])return{};const _0x32e611=(0x0,metric_logger_1[a3_0xd726('0x21')])('startRun');try{const _0x565015={'meta':{'nxCloudVersion':this[a3_0xd726('0x2a')]()},'branch':(0x0,environment_1[a3_0xd726('0x1d')])(),'runGroup':(0x0,environment_1['getRunGroup'])(),'ciExecutionId':(0x0,environment_1['getCIExecutionId'])(),'ciExecutionEnv':(0x0,environment_1[a3_0xd726('0x13')])(),'distributedExecutionId':_0x24b5cd,'hashes':_0x436af0};if(environment_1['VERBOSE_LOGGING']){output[a3_0xd726('0x0')]({'title':a3_0xd726('0x1e'),'bodyLines':['\x0a'+JSON[a3_0xd726('0x6')](_0x565015,null,0x2)]});}const _0x595151=yield(0x0,axios_1[a3_0xd726('0x15')])('RunStart\x20duration',()=>(0x0,axios_1['axiosMultipleTries'])(()=>this['apiAxiosInstance'][a3_0xd726('0x46')]('/nx-cloud/runs/start',_0x565015)));_0x32e611['recordMetric']((0x0,metric_logger_1[a3_0xd726('0x36')])(_0x595151));if(_0x595151['data']&&_0x595151[a3_0xd726('0x3')][a3_0xd726('0x2')]){this[a3_0xd726('0x3c')][a3_0xd726('0x2')]=_0x595151[a3_0xd726('0x3')][a3_0xd726('0x2')];}if(!_0x595151[a3_0xd726('0x3')]||!_0x595151[a3_0xd726('0x3')][a3_0xd726('0x37')]){this[a3_0xd726('0x3c')]['apiError']=a3_0xd726('0x24')+JSON[a3_0xd726('0x6')](_0x595151['data']);return{};}return _0x595151['data'][a3_0xd726('0x37')];}catch(_0x59ed0f){_0x32e611[a3_0xd726('0x2b')](((_0x18881b=_0x59ed0f===null||_0x59ed0f===void 0x0?void 0x0:_0x59ed0f[a3_0xd726('0x8')])===null||_0x18881b===void 0x0?void 0x0:_0x18881b[a3_0xd726('0x45')])?(0x0,metric_logger_1[a3_0xd726('0x36')])(_0x59ed0f[a3_0xd726('0x8')]['response']):metric_logger_1[a3_0xd726('0xf')]);this[a3_0xd726('0x3c')][a3_0xd726('0x22')]=this[a3_0xd726('0x3c')][a3_0xd726('0x2e')](_0x59ed0f,a3_0xd726('0x14'));return{};}});}[a3_0xd726('0x32')](_0x37f6ec,_0x425e32,_0x5e88ff,_0x590fef){if((0x0,is_private_cloud_1['isConnectedToPrivateCloud'])()){for(let _0x52e0e7 of _0x425e32){delete _0x52e0e7[a3_0xd726('0x20')];}}const _0x1a4076=Object[a3_0xd726('0x31')](Object[a3_0xd726('0x31')]({'meta':{'nxCloudVersion':this[a3_0xd726('0x2a')]()},'tasks':_0x425e32,'run':_0x37f6ec,'linkId':_0x590fef},(0x0,is_private_cloud_1[a3_0xd726('0x3f')])()?{}:_0x5e88ff),{'machineInfo':this[a3_0xd726('0x12')]});return JSON['stringify'](_0x1a4076);}[a3_0xd726('0xc')](_0x1f9603,_0x61047a,_0x2b3162,_0x176855){var _0x52f68e,_0x1ce348;return __awaiter(this,void 0x0,void 0x0,function*(){if(this[a3_0xd726('0x3c')][a3_0xd726('0x22')])return![];let _0xb97c22=this[a3_0xd726('0x32')](_0x1f9603,_0x61047a,_0x2b3162,_0x176855);if(_0xb97c22[a3_0xd726('0x23')]>0x14*0x3e8*0x3e8){_0xb97c22=this[a3_0xd726('0x32')](_0x1f9603,_0x61047a[a3_0xd726('0x1b')](_0x5b5d3a=>Object['assign'](Object[a3_0xd726('0x31')]({},_0x5b5d3a),{'hashDetails':undefined})),_0x2b3162,_0x176855);}const _0x11ad0a=Buffer[a3_0xd726('0x38')](_0xb97c22);const _0x5d9fb6=yield(0x0,util_1[a3_0xd726('0x27')])(zlib_1['gzip'])(_0x11ad0a);const _0x5d6cd5=(0x0,metric_logger_1['createMetricRecorder'])(a3_0xd726('0xc'));try{if(environment_1['VERBOSE_LOGGING']){const _0x173d95=_0x61047a[a3_0xd726('0x1b')](_0x5d0944=>{return Object[a3_0xd726('0x31')](Object[a3_0xd726('0x31')]({},_0x5d0944),{'terminalOutput':_0x5d0944['terminalOutput']?_0x5d0944[a3_0xd726('0x2f')][a3_0xd726('0x11')](0x0,0x14)+a3_0xd726('0x17'):undefined});});output[a3_0xd726('0x0')]({'title':'RunEnd.\x20Completed\x20tasks','bodyLines':['\x0a'+JSON['stringify'](_0x173d95,null,0x2)]});}const _0xe6d9ed=yield(0x0,axios_1['printDuration'])('RunEnd\x20duration',()=>(0x0,axios_1['axiosMultipleTries'])(()=>this[a3_0xd726('0x16')][a3_0xd726('0x46')]('/nx-cloud/runs/end',_0x5d9fb6,{'headers':Object['assign'](Object[a3_0xd726('0x31')]({},this[a3_0xd726('0x16')][a3_0xd726('0x40')][a3_0xd726('0x10')]),{'Content-Encoding':a3_0xd726('0xd'),'Content-Type':a3_0xd726('0x1c')})})));if(_0xe6d9ed){_0x5d6cd5[a3_0xd726('0x2b')]((0x0,metric_logger_1[a3_0xd726('0x36')])(_0xe6d9ed));if(_0xe6d9ed[a3_0xd726('0x3')]&&_0xe6d9ed[a3_0xd726('0x3')][a3_0xd726('0x5')]&&_0xe6d9ed[a3_0xd726('0x3')][a3_0xd726('0x26')]===a3_0xd726('0x3a')){this[a3_0xd726('0x3d')]['runUrl']=_0xe6d9ed[a3_0xd726('0x3')][a3_0xd726('0x5')];return!![];}if(_0xe6d9ed[a3_0xd726('0x3')]&&_0xe6d9ed['data']['status']){this[a3_0xd726('0x3c')][a3_0xd726('0x22')]=a3_0xd726('0xa')+JSON[a3_0xd726('0x6')](_0xe6d9ed['data'][a3_0xd726('0x2')]);}else if(_0xe6d9ed[a3_0xd726('0x3')]&&typeof _0xe6d9ed['data']===a3_0xd726('0x29')){if(_0xe6d9ed[a3_0xd726('0x3')]!==a3_0xd726('0x3a')){this[a3_0xd726('0x3c')][a3_0xd726('0x22')]=a3_0xd726('0xa')+JSON[a3_0xd726('0x6')](_0xe6d9ed[a3_0xd726('0x3')]);}}else{this[a3_0xd726('0x3c')][a3_0xd726('0x22')]=a3_0xd726('0xa')+JSON['stringify'](_0xe6d9ed[a3_0xd726('0x3')]);}if(environment_1['VERBOSE_LOGGING']){output['note']({'title':a3_0xd726('0x18'),'bodyLines':[JSON[a3_0xd726('0x6')](_0xe6d9ed[a3_0xd726('0x3')],null,0x2)]});}}else{output[a3_0xd726('0x9')]({'title':a3_0xd726('0x28'),'bodyLines':[a3_0xd726('0x2d'),a3_0xd726('0x35'),JSON[a3_0xd726('0x6')](_0x1f9603,null,0x2),'Stack\x20Trace:',JSON['stringify'](new Error()[a3_0xd726('0x1a')],null,0x2)]});}return![];}catch(_0x2d2b66){_0x5d6cd5[a3_0xd726('0x2b')](((_0x52f68e=_0x2d2b66===null||_0x2d2b66===void 0x0?void 0x0:_0x2d2b66[a3_0xd726('0x8')])===null||_0x52f68e===void 0x0?void 0x0:_0x52f68e['response'])?(0x0,metric_logger_1['mapRespToPerfEntry'])(_0x2d2b66[a3_0xd726('0x8')][a3_0xd726('0x45')]):metric_logger_1[a3_0xd726('0xf')]);const _0x32df41=(_0x1ce348=_0x2d2b66[a3_0xd726('0x8')])!==null&&_0x1ce348!==void 0x0?_0x1ce348:_0x2d2b66;this[a3_0xd726('0x3c')][a3_0xd726('0x22')]=this[a3_0xd726('0x3c')]['extractErrorMessage'](_0x32df41,a3_0xd726('0x14'));return![];}});}['nxCloudVersion'](){try{const _0x2923df=JSON[a3_0xd726('0x42')]((0x0,fs_1[a3_0xd726('0x1')])('package.json')[a3_0xd726('0xb')]());return _0x2923df[a3_0xd726('0x7')]['@nrwl/nx-cloud'];}catch(_0x3d63f0){return a3_0xd726('0x41');}}}exports[a3_0xd726('0x43')]=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 is_private_cloud_1 = require("../../../utilities/is-private-cloud");
20
+ const { output } = require('../../../utilities/nx-imports');
21
+ class CloudRunApi {
22
+ constructor(messages, runContext, options, machineInfo) {
23
+ this.messages = messages;
24
+ this.runContext = runContext;
25
+ this.machineInfo = machineInfo;
26
+ this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options);
27
+ }
28
+ startRun(distributedExecutionId, hashes) {
29
+ var _a;
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ // API is not working, don't make the end request
32
+ if (this.messages.apiError)
33
+ return {};
34
+ const recorder = (0, metric_logger_1.createMetricRecorder)('startRun');
35
+ try {
36
+ const request = {
37
+ meta: {
38
+ nxCloudVersion: this.nxCloudVersion(),
39
+ },
40
+ branch: (0, environment_1.getBranch)(),
41
+ runGroup: (0, environment_1.getRunGroup)(),
42
+ ciExecutionId: (0, environment_1.getCIExecutionId)(),
43
+ ciExecutionEnv: (0, environment_1.getCIExecutionEnv)(),
44
+ distributedExecutionId,
45
+ hashes,
46
+ };
47
+ if (environment_1.VERBOSE_LOGGING) {
48
+ output.note({
49
+ title: 'RunStart',
50
+ bodyLines: ['\n' + JSON.stringify(request, null, 2)],
51
+ });
52
+ }
53
+ const resp = yield (0, axios_1.printDuration)('RunStart duration', () => (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/runs/start', request)));
54
+ recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
55
+ if (resp.data && resp.data.message) {
56
+ this.messages.message = resp.data.message;
57
+ }
58
+ if (!resp.data || !resp.data.urls) {
59
+ this.messages.apiError = `Invalid Nx Cloud response: ${JSON.stringify(resp.data)}`;
60
+ return {};
61
+ }
62
+ return resp.data.urls;
63
+ }
64
+ catch (e) {
65
+ recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
66
+ ? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
67
+ : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
68
+ this.messages.apiError = this.messages.extractErrorMessage(e, 'api');
69
+ return {};
70
+ }
71
+ });
72
+ }
73
+ createReqBody(run, tasks, ciExecutionContext, linkId) {
74
+ if ((0, is_private_cloud_1.isConnectedToPrivateCloud)()) {
75
+ for (let t of tasks) {
76
+ delete t.uploadedToStorage;
77
+ }
78
+ }
79
+ const uncompressedReqBody = Object.assign(Object.assign({ meta: {
80
+ nxCloudVersion: this.nxCloudVersion(),
81
+ }, tasks,
82
+ run,
83
+ linkId }, ((0, is_private_cloud_1.isConnectedToPrivateCloud)() ? {} : ciExecutionContext)), { machineInfo: this.machineInfo });
84
+ return JSON.stringify(uncompressedReqBody);
85
+ }
86
+ endRun(run, tasks, ciExecutionContext, linkId) {
87
+ var _a, _b;
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ // API is not working, don't make the end request
90
+ if (this.messages.apiError)
91
+ return false;
92
+ let uncompressedBodyString = this.createReqBody(run, tasks, ciExecutionContext, linkId);
93
+ // if the req body is > 20mb, remove hashDetails
94
+ if (uncompressedBodyString.length > 20 * 1000 * 1000) {
95
+ uncompressedBodyString = this.createReqBody(run, tasks.map((t) => (Object.assign(Object.assign({}, t), { hashDetails: undefined }))), ciExecutionContext, linkId);
96
+ }
97
+ const uncompressedBuffer = Buffer.from(uncompressedBodyString);
98
+ const compressedBuffer = yield (0, util_1.promisify)(zlib_1.gzip)(uncompressedBuffer);
99
+ const recorder = (0, metric_logger_1.createMetricRecorder)('endRun');
100
+ try {
101
+ if (environment_1.VERBOSE_LOGGING) {
102
+ const t = tasks.map((tt) => {
103
+ return Object.assign(Object.assign({}, tt), { terminalOutput: tt.terminalOutput
104
+ ? `${tt.terminalOutput.slice(0, 20)}...`
105
+ : undefined });
106
+ });
107
+ output.note({
108
+ title: 'RunEnd. Completed tasks',
109
+ bodyLines: ['\n' + JSON.stringify(t, null, 2)],
110
+ });
111
+ }
112
+ const resp = yield (0, axios_1.printDuration)('RunEnd duration', () => (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/runs/end', compressedBuffer, {
113
+ headers: Object.assign(Object.assign({}, this.apiAxiosInstance.defaults.headers), { 'Content-Encoding': 'gzip', 'Content-Type': 'application/octet-stream' }),
114
+ })));
115
+ if (resp) {
116
+ recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
117
+ if (resp.data && resp.data.runUrl && resp.data.status === 'success') {
118
+ this.runContext.runUrl = resp.data.runUrl;
119
+ return true;
120
+ }
121
+ if (resp.data && resp.data.status) {
122
+ this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data.message)}`;
123
+ }
124
+ else if (resp.data && typeof resp.data === 'string') {
125
+ if (resp.data !== 'success') {
126
+ this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data)}`;
127
+ }
128
+ }
129
+ else {
130
+ this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data)}`;
131
+ }
132
+ if (environment_1.VERBOSE_LOGGING) {
133
+ output.note({
134
+ title: 'Invalid end run response',
135
+ bodyLines: [JSON.stringify(resp.data, null, 2)],
136
+ });
137
+ }
138
+ }
139
+ else {
140
+ output.error({
141
+ title: 'Nx Cloud: Unknown Error Occurred',
142
+ bodyLines: [
143
+ 'Run completion responded with `undefined`.',
144
+ 'Run Details:',
145
+ JSON.stringify(run, null, 2),
146
+ 'Stack Trace:',
147
+ JSON.stringify(new Error().stack, null, 2),
148
+ ],
149
+ });
150
+ }
151
+ return false;
152
+ }
153
+ catch (ee) {
154
+ recorder.recordMetric(((_a = ee === null || ee === void 0 ? void 0 : ee.axiosException) === null || _a === void 0 ? void 0 : _a.response)
155
+ ? (0, metric_logger_1.mapRespToPerfEntry)(ee.axiosException.response)
156
+ : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
157
+ const e = (_b = ee.axiosException) !== null && _b !== void 0 ? _b : ee;
158
+ this.messages.apiError = this.messages.extractErrorMessage(e, 'api');
159
+ return false;
160
+ }
161
+ });
162
+ }
163
+ nxCloudVersion() {
164
+ try {
165
+ const v = JSON.parse((0, fs_1.readFileSync)(`package.json`).toString());
166
+ return v.devDependencies['@nrwl/nx-cloud'];
167
+ }
168
+ catch (e) {
169
+ return 'unknown';
170
+ }
171
+ }
172
+ }
173
+ exports.CloudRunApi = CloudRunApi;
174
+ //# sourceMappingURL=cloud-run.api.js.map
@@ -1 +1,16 @@
1
- const a4_0xfd23=['0123456789','random','__esModule','length','generateUniqueLinkId','toLowerCase','defineProperty','ABCDEFGHIJKLMNOPQRSTUVWXYZ'];(function(_0x4de115,_0xfd2348){const _0x2ba961=function(_0x40c3dc){while(--_0x40c3dc){_0x4de115['push'](_0x4de115['shift']());}};_0x2ba961(++_0xfd2348);}(a4_0xfd23,0x1ab));const a4_0x2ba9=function(_0x4de115,_0xfd2348){_0x4de115=_0x4de115-0x0;let _0x2ba961=a4_0xfd23[_0x4de115];return _0x2ba961;};'use strict';Object[a4_0x2ba9('0x3')](exports,a4_0x2ba9('0x7'),{'value':!![]});exports[a4_0x2ba9('0x1')]=void 0x0;const upper=a4_0x2ba9('0x4');const digits=a4_0x2ba9('0x5');const lower=upper[a4_0x2ba9('0x2')]();const alphanum=upper+lower+digits;function generateUniqueLinkId(){let _0x3e16f8='';for(let _0x162968=0x0;_0x162968<0xa;++_0x162968){_0x3e16f8+=alphanum[Math['floor'](Math[a4_0x2ba9('0x6')]()*alphanum[a4_0x2ba9('0x0')])];}return _0x3e16f8;}exports[a4_0x2ba9('0x1')]=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,93 @@
1
- const a5_0x2e2a=['runGroup:\x20','ciExecutionId','note','createMetricRecorder','dtePollTasks','response','error','DistributedAgentApi','../../../utilities/metric-logger','__awaiter','agentName','Completed\x20run\x20group\x20with\x20an\x20error','value','post','recordMetric','ciExecutionEnv','../../../utilities/environment','error:\x20','then','../../../utilities/axios','ciExecutionId:\x20','done','data','RUNNER_FAILURE_PERF_ENTRY','axiosMultipleTries','completeRunGroupWithError','apply','runGroup','next','/nx-cloud/executions/tasks','/nx-cloud/executions/complete-run-group','__esModule','Completing\x20with\x20an\x20error','axiosException','branch','mapRespToPerfEntry','apiAxiosInstance'];(function(_0x557416,_0x2e2a7f){const _0x7b751e=function(_0x271f7c){while(--_0x271f7c){_0x557416['push'](_0x557416['shift']());}};_0x7b751e(++_0x2e2a7f);}(a5_0x2e2a,0x1cb));const a5_0x7b75=function(_0x557416,_0x2e2a7f){_0x557416=_0x557416-0x0;let _0x7b751e=a5_0x2e2a[_0x557416];return _0x7b751e;};'use strict';var __awaiter=this&&this[a5_0x7b75('0x1f')]||function(_0x559730,_0x5e3b29,_0x162243,_0x3b0759){function _0x27b25d(_0x516e4e){return _0x516e4e instanceof _0x162243?_0x516e4e:new _0x162243(function(_0x440b30){_0x440b30(_0x516e4e);});}return new(_0x162243||(_0x162243=Promise))(function(_0x5c4a4b,_0x5cdd15){function _0x343481(_0x17c4f8){try{_0x1f76f6(_0x3b0759[a5_0x7b75('0xd')](_0x17c4f8));}catch(_0x58c379){_0x5cdd15(_0x58c379);}}function _0x155538(_0x5e0ae6){try{_0x1f76f6(_0x3b0759['throw'](_0x5e0ae6));}catch(_0x1f04ff){_0x5cdd15(_0x1f04ff);}}function _0x1f76f6(_0x4bf366){_0x4bf366[a5_0x7b75('0x6')]?_0x5c4a4b(_0x4bf366[a5_0x7b75('0x22')]):_0x27b25d(_0x4bf366['value'])[a5_0x7b75('0x3')](_0x343481,_0x155538);}_0x1f76f6((_0x3b0759=_0x3b0759[a5_0x7b75('0xb')](_0x559730,_0x5e3b29||[]))[a5_0x7b75('0xd')]());});};Object['defineProperty'](exports,a5_0x7b75('0x10'),{'value':!![]});exports[a5_0x7b75('0x1d')]=void 0x0;const axios_1=require(a5_0x7b75('0x4'));const environment_1=require(a5_0x7b75('0x1'));const metric_logger_1=require(a5_0x7b75('0x1e'));const {output}=require('../../../utilities/nx-imports');class DistributedAgentApi{constructor(_0x23ecc8,_0x28c67b,_0x5242ee,_0x5a4586,_0x27e538,_0x64d91e){this[a5_0x7b75('0x13')]=_0x28c67b;this[a5_0x7b75('0xc')]=_0x5242ee;this['ciExecutionId']=_0x5a4586;this['ciExecutionEnv']=_0x27e538;this[a5_0x7b75('0x20')]=_0x64d91e;this[a5_0x7b75('0x15')]=(0x0,axios_1['createApiAxiosInstance'])(_0x23ecc8);}['tasks'](_0x359f4e,_0x29dafe,_0x1eb0e3,_0x4048d6){var _0x31c85a;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x272c38=(0x0,metric_logger_1[a5_0x7b75('0x19')])(a5_0x7b75('0x1a'));try{const _0x500a3c=yield(0x0,axios_1[a5_0x7b75('0x9')])(()=>this[a5_0x7b75('0x15')][a5_0x7b75('0x23')](a5_0x7b75('0xe'),{'runGroup':this[a5_0x7b75('0xc')],'ciExecutionId':this[a5_0x7b75('0x17')],'ciExecutionEnv':this[a5_0x7b75('0x0')],'agentName':this[a5_0x7b75('0x20')],'executionId':_0x359f4e,'statusCode':_0x29dafe,'completedTasks':_0x1eb0e3,'targets':_0x4048d6}));_0x272c38[a5_0x7b75('0x24')]((0x0,metric_logger_1[a5_0x7b75('0x14')])(_0x500a3c));return _0x500a3c[a5_0x7b75('0x7')];}catch(_0x55c02c){_0x272c38[a5_0x7b75('0x24')](((_0x31c85a=_0x55c02c===null||_0x55c02c===void 0x0?void 0x0:_0x55c02c[a5_0x7b75('0x12')])===null||_0x31c85a===void 0x0?void 0x0:_0x31c85a['response'])?(0x0,metric_logger_1[a5_0x7b75('0x14')])(_0x55c02c[a5_0x7b75('0x12')][a5_0x7b75('0x1b')]):metric_logger_1[a5_0x7b75('0x8')]);throw _0x55c02c;}});}[a5_0x7b75('0xa')](_0x5e08fd){var _0x9a31c1;return __awaiter(this,void 0x0,void 0x0,function*(){if(environment_1['VERBOSE_LOGGING']){output[a5_0x7b75('0x18')]({'title':a5_0x7b75('0x11'),'bodyLines':[a5_0x7b75('0x5')+this[a5_0x7b75('0x17')],'ciExecutionEnv:\x20'+this[a5_0x7b75('0x0')],a5_0x7b75('0x16')+this[a5_0x7b75('0xc')],a5_0x7b75('0x2')+_0x5e08fd]});}const _0x46e3f4=(0x0,metric_logger_1[a5_0x7b75('0x19')])('completeRunGroup');try{const _0x422884=yield(0x0,axios_1[a5_0x7b75('0x9')])(()=>this[a5_0x7b75('0x15')][a5_0x7b75('0x23')](a5_0x7b75('0xf'),{'branch':this[a5_0x7b75('0x13')],'runGroup':this[a5_0x7b75('0xc')],'ciExecutionId':this[a5_0x7b75('0x17')],'ciExecutionEnv':this[a5_0x7b75('0x0')],'agentName':this[a5_0x7b75('0x20')],'criticalErrorMessage':_0x5e08fd}));if(environment_1['VERBOSE_LOGGING']){output[a5_0x7b75('0x18')]({'title':a5_0x7b75('0x21')});}_0x46e3f4[a5_0x7b75('0x24')]((0x0,metric_logger_1['mapRespToPerfEntry'])(_0x422884));}catch(_0x148bc7){_0x46e3f4[a5_0x7b75('0x24')](((_0x9a31c1=_0x148bc7===null||_0x148bc7===void 0x0?void 0x0:_0x148bc7['axiosException'])===null||_0x9a31c1===void 0x0?void 0x0:_0x9a31c1[a5_0x7b75('0x1b')])?(0x0,metric_logger_1[a5_0x7b75('0x14')])(_0x148bc7[a5_0x7b75('0x12')][a5_0x7b75('0x1b')]):metric_logger_1[a5_0x7b75('0x8')]);console[a5_0x7b75('0x1c')](_0x148bc7);}});}}exports[a5_0x7b75('0x1d')]=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, branch, runGroup, ciExecutionId, ciExecutionEnv, agentName) {
19
+ this.branch = branch;
20
+ this.runGroup = runGroup;
21
+ this.ciExecutionId = ciExecutionId;
22
+ this.ciExecutionEnv = ciExecutionEnv;
23
+ this.agentName = agentName;
24
+ this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options);
25
+ }
26
+ tasks(executionId, statusCode, completedTasks, targets) {
27
+ var _a;
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const recorder = (0, metric_logger_1.createMetricRecorder)('dtePollTasks');
30
+ try {
31
+ const res = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/tasks', {
32
+ runGroup: this.runGroup,
33
+ ciExecutionId: this.ciExecutionId,
34
+ ciExecutionEnv: this.ciExecutionEnv,
35
+ agentName: this.agentName,
36
+ executionId,
37
+ statusCode,
38
+ completedTasks,
39
+ targets,
40
+ }));
41
+ recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(res));
42
+ return res.data;
43
+ }
44
+ catch (e) {
45
+ recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
46
+ ? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
47
+ : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
48
+ throw e;
49
+ }
50
+ });
51
+ }
52
+ completeRunGroupWithError(error) {
53
+ var _a;
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ if (environment_1.VERBOSE_LOGGING) {
56
+ output.note({
57
+ title: 'Completing with an error',
58
+ bodyLines: [
59
+ `ciExecutionId: ${this.ciExecutionId}`,
60
+ `ciExecutionEnv: ${this.ciExecutionEnv}`,
61
+ `runGroup: ${this.runGroup}`,
62
+ `error: ${error}`,
63
+ ],
64
+ });
65
+ }
66
+ const recorder = (0, metric_logger_1.createMetricRecorder)('completeRunGroup');
67
+ try {
68
+ const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/complete-run-group', {
69
+ branch: this.branch,
70
+ runGroup: this.runGroup,
71
+ ciExecutionId: this.ciExecutionId,
72
+ ciExecutionEnv: this.ciExecutionEnv,
73
+ agentName: this.agentName,
74
+ criticalErrorMessage: error,
75
+ }));
76
+ if (environment_1.VERBOSE_LOGGING) {
77
+ output.note({
78
+ title: 'Completed run group with an error',
79
+ });
80
+ }
81
+ recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
82
+ }
83
+ catch (e) {
84
+ recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
85
+ ? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
86
+ : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
87
+ console.error(e);
88
+ }
89
+ });
90
+ }
91
+ }
92
+ exports.DistributedAgentApi = DistributedAgentApi;
93
+ //# sourceMappingURL=distributed-agent.api.js.map