@nrwl/nx-cloud 15.1.1 → 15.2.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/lib/core/api/error-reporter.api.js +36 -1
  2. package/lib/core/api/run-group.api.js +68 -1
  3. package/lib/core/models/distributed-agent/tasks-api-response.model.d.ts +5 -0
  4. package/lib/core/models/run-context.model.d.ts +2 -2
  5. package/lib/core/runners/cloud-enabled/cloud-enabled-life-cycle.js +92 -1
  6. package/lib/core/runners/cloud-enabled/cloud-enabled.runner.js +305 -1
  7. package/lib/core/runners/cloud-enabled/cloud-enabled.runner.js.map +1 -1
  8. package/lib/core/runners/cloud-enabled/cloud-remote-cache.js +117 -1
  9. package/lib/core/runners/cloud-enabled/cloud-run.api.js +167 -1
  10. package/lib/core/runners/cloud-enabled/id-generator.js +16 -1
  11. package/lib/core/runners/distributed-agent/distributed-agent.api.js +80 -1
  12. package/lib/core/runners/distributed-agent/distributed-agent.impl.js +154 -1
  13. package/lib/core/runners/distributed-agent/distributed-agent.impl.js.map +1 -1
  14. package/lib/core/runners/distributed-agent/execute-tasks.d.ts +10 -0
  15. package/lib/core/runners/distributed-agent/execute-tasks.js +114 -0
  16. package/lib/core/runners/distributed-agent/execute-tasks.js.map +1 -0
  17. package/lib/core/runners/distributed-agent/invoke-tasks-using-nx-imperative-api.d.ts +9 -0
  18. package/lib/core/runners/distributed-agent/invoke-tasks-using-nx-imperative-api.js +50 -0
  19. package/lib/core/runners/distributed-agent/invoke-tasks-using-nx-imperative-api.js.map +1 -0
  20. package/lib/core/runners/distributed-agent/invoke-tasks-using-run-many.d.ts +9 -0
  21. package/lib/core/runners/distributed-agent/invoke-tasks-using-run-many.js +97 -0
  22. package/lib/core/runners/distributed-agent/invoke-tasks-using-run-many.js.map +1 -0
  23. package/lib/core/runners/distributed-execution/distributed-execution.api.js +143 -1
  24. package/lib/core/runners/distributed-execution/distributed-execution.runner.js +115 -1
  25. package/lib/core/runners/distributed-execution/distributed-execution.runner.js.map +1 -1
  26. package/lib/core/runners/distributed-execution/process-task.d.ts +7 -0
  27. package/lib/core/runners/distributed-execution/process-task.js +45 -0
  28. package/lib/core/runners/distributed-execution/process-task.js.map +1 -0
  29. package/lib/core/runners/distributed-execution/process-tasks.d.ts +7 -0
  30. package/lib/core/runners/distributed-execution/process-tasks.js +67 -0
  31. package/lib/core/runners/distributed-execution/process-tasks.js.map +1 -0
  32. package/lib/core/runners/distributed-execution/split-task-graph-into-stages.js +37 -1
  33. package/lib/core/runners/distributed-execution/task-graph-creator.d.ts +2 -0
  34. package/lib/core/runners/distributed-execution/task-graph-creator.js +100 -1
  35. package/lib/core/runners/distributed-execution/task-graph-creator.js.map +1 -1
  36. package/lib/daemon/process-run-end.js +2 -3
  37. package/lib/daemon/process-run-end.js.map +1 -1
  38. package/lib/nx-cloud-tasks-runner.js +4 -2
  39. package/lib/nx-cloud-tasks-runner.js.map +1 -1
  40. package/lib/utilities/dte-artifact-storage.d.ts +7 -0
  41. package/lib/utilities/dte-artifact-storage.js +42 -0
  42. package/lib/utilities/dte-artifact-storage.js.map +1 -0
  43. package/lib/utilities/nx-imports.js +17 -9
  44. package/lib/utilities/nx-imports.js.map +1 -1
  45. package/lib/utilities/serializer-overrides.d.ts +1 -0
  46. package/lib/utilities/serializer-overrides.js +2 -1
  47. package/lib/utilities/serializer-overrides.js.map +1 -1
  48. package/package.json +1 -1
@@ -1 +1,117 @@
1
- const a2_0x5cfb=['messages','extractErrorMessage','note','waitForStoreRequestsToComplete','VERBOSE_LOGGING','cache-miss','status','requests','../../../utilities/environment','.\x20Status\x20404.','fileStorage','../../../utilities/nx-imports','resolve','all','push','apply','throw','retrieve','store','axiosException','value','__awaiter','reduce','done','Nx\x20Cloud:\x20Skipping\x20storing\x20','next','cacheError','filter','response','hashUrls','NX_CLOUD_DISTRIBUTED_EXECUTION_ID','CloudRemoteCache','startRun','statuses','Nx\x20Cloud:\x20Cache\x20miss\x20','forEach','__esModule','put','runContext','indexOf','storage','Maybe\x20you\x20are\x20using\x20a\x20read-only\x20token\x20or\x20the\x20artifact\x20has\x20already\x20being\x20uploaded.','hash'];(function(_0x6086b7,_0x5cfb4b){const _0x344982=function(_0x51e5a1){while(--_0x51e5a1){_0x6086b7['push'](_0x6086b7['shift']());}};_0x344982(++_0x5cfb4b);}(a2_0x5cfb,0x7d));const a2_0x3449=function(_0x6086b7,_0x5cfb4b){_0x6086b7=_0x6086b7-0x0;let _0x344982=a2_0x5cfb[_0x6086b7];return _0x344982;};'use strict';var __awaiter=this&&this[a2_0x3449('0x19')]||function(_0x407169,_0x3ac636,_0x455e38,_0x2455b9){function _0x317245(_0x224f9c){return _0x224f9c instanceof _0x455e38?_0x224f9c:new _0x455e38(function(_0x333e7e){_0x333e7e(_0x224f9c);});}return new(_0x455e38||(_0x455e38=Promise))(function(_0x2fc9aa,_0x4bd3e5){function _0x330017(_0x42f806){try{_0x38eeb9(_0x2455b9[a2_0x3449('0x1d')](_0x42f806));}catch(_0x1f232c){_0x4bd3e5(_0x1f232c);}}function _0x4e6b98(_0xfbe599){try{_0x38eeb9(_0x2455b9[a2_0x3449('0x14')](_0xfbe599));}catch(_0x5eaf61){_0x4bd3e5(_0x5eaf61);}}function _0x38eeb9(_0x4ad1a8){_0x4ad1a8[a2_0x3449('0x1b')]?_0x2fc9aa(_0x4ad1a8[a2_0x3449('0x18')]):_0x317245(_0x4ad1a8[a2_0x3449('0x18')])['then'](_0x330017,_0x4e6b98);}_0x38eeb9((_0x2455b9=_0x2455b9[a2_0x3449('0x13')](_0x407169,_0x3ac636||[]))[a2_0x3449('0x1d')]());});};Object['defineProperty'](exports,a2_0x3449('0x28'),{'value':!![]});exports[a2_0x3449('0x23')]=void 0x0;const environment_1=require(a2_0x3449('0xc'));const {output}=require(a2_0x3449('0xf'));class CloudRemoteCache{constructor(_0x38b34a,_0x2e60f4,_0x51025a,_0x34cd7c){this['messages']=_0x38b34a;this['api']=_0x2e60f4;this[a2_0x3449('0x2a')]=_0x51025a;this[a2_0x3449('0xe')]=_0x34cd7c;this['storeRequests']=[];}[a2_0x3449('0x15')](_0x477a9f,_0x15587){var _0x263a06;return __awaiter(this,void 0x0,void 0x0,function*(){if(this['messages'][a2_0x3449('0x1e')])return![];const _0x495886=yield this[a2_0x3449('0x21')](_0x477a9f);if(!_0x495886||!_0x495886['get']){if(environment_1[a2_0x3449('0x8')]){output['note']({'title':a2_0x3449('0x26')+_0x477a9f+'.'});}this[a2_0x3449('0x2a')][a2_0x3449('0x25')][_0x477a9f]=a2_0x3449('0x9');return![];}try{yield this[a2_0x3449('0xe')]['retrieve'](_0x477a9f,_0x495886['get'],_0x15587);this[a2_0x3449('0x2a')][a2_0x3449('0x25')][_0x477a9f]='remote-cache-hit';return!![];}catch(_0x5b43b9){const _0x4b2cb8=(_0x263a06=_0x5b43b9[a2_0x3449('0x17')])!==null&&_0x263a06!==void 0x0?_0x263a06:_0x5b43b9;if(_0x4b2cb8['response']&&_0x4b2cb8[a2_0x3449('0x20')][a2_0x3449('0xa')]===0x194){if(environment_1[a2_0x3449('0x8')]){output[a2_0x3449('0x6')]({'title':a2_0x3449('0x26')+_0x477a9f+a2_0x3449('0xd')});}}else{this[a2_0x3449('0x4')][a2_0x3449('0x1e')]=this['messages'][a2_0x3449('0x5')](_0x4b2cb8,a2_0x3449('0x1'));}this[a2_0x3449('0x2a')][a2_0x3449('0x25')][_0x477a9f]='cache-miss';return![];}});}[a2_0x3449('0x16')](_0x2f6fe7,_0x53ba10){return __awaiter(this,void 0x0,void 0x0,function*(){if(this['messages'][a2_0x3449('0x1e')])return![];const _0x47fe14=Promise[a2_0x3449('0x10')]()['then'](()=>__awaiter(this,void 0x0,void 0x0,function*(){var _0x5b5710;const _0x175225=yield this[a2_0x3449('0x21')](_0x2f6fe7);if(!_0x175225)return![];if(!_0x175225[a2_0x3449('0x29')]){if(environment_1[a2_0x3449('0x8')]){output[a2_0x3449('0x6')]({'title':a2_0x3449('0x1c')+_0x2f6fe7+'.','bodyLines':['There\x20are\x20several\x20reasons\x20why\x20this\x20can\x20happen.',a2_0x3449('0x2')]});}return!![];}try{yield this['fileStorage']['store'](_0x2f6fe7,_0x175225[a2_0x3449('0x29')],_0x53ba10);return!![];}catch(_0x17287f){const _0x1c1441=(_0x5b5710=_0x17287f[a2_0x3449('0x17')])!==null&&_0x5b5710!==void 0x0?_0x5b5710:_0x17287f;this[a2_0x3449('0x4')]['cacheError']=this[a2_0x3449('0x4')][a2_0x3449('0x5')](_0x1c1441,'storage');return![];}}));this['storeRequests'][a2_0x3449('0x12')](_0x47fe14);return _0x47fe14;});}[a2_0x3449('0x21')](_0x3b0fae){return __awaiter(this,void 0x0,void 0x0,function*(){if(_0x3b0fae in this[a2_0x3449('0x2a')]['requests']){return(yield this[a2_0x3449('0x2a')][a2_0x3449('0xb')][_0x3b0fae])[_0x3b0fae];}else{const _0x1a6c3f=this['runContext']['scheduledTasks'][a2_0x3449('0x1f')](_0x1701e1=>!this[a2_0x3449('0x2a')]['requests'][_0x1701e1[a2_0x3449('0x3')]])['map'](_0x3d8e81=>_0x3d8e81[a2_0x3449('0x3')]);if(_0x1a6c3f[a2_0x3449('0x0')](_0x3b0fae)===-0x1){_0x1a6c3f[a2_0x3449('0x12')](_0x3b0fae);}const _0x192f51=this['api'][a2_0x3449('0x24')](environment_1[a2_0x3449('0x22')],_0x1a6c3f);_0x1a6c3f[a2_0x3449('0x27')](_0x7bd2c9=>{this[a2_0x3449('0x2a')][a2_0x3449('0xb')][_0x7bd2c9]=_0x192f51;});return(yield _0x192f51)[_0x3b0fae];}});}[a2_0x3449('0x7')](){return Promise[a2_0x3449('0x11')](this['storeRequests'])['then'](_0x27e6b9=>_0x27e6b9[a2_0x3449('0x1a')]((_0x3c4323,_0x51c4dc)=>_0x3c4323&&_0x51c4dc,!![]));}}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}.`,
70
+ bodyLines: [
71
+ `There are several reasons why this can happen.`,
72
+ `Maybe you are using a read-only token or the artifact has already being uploaded.`,
73
+ ],
74
+ });
75
+ }
76
+ return true;
77
+ }
78
+ try {
79
+ yield this.fileStorage.store(hash, hashUrls.put, cacheDirectory);
80
+ return true;
81
+ }
82
+ catch (ee) {
83
+ const e = (_a = ee.axiosException) !== null && _a !== void 0 ? _a : ee;
84
+ this.messages.cacheError = this.messages.extractErrorMessage(e, 'storage');
85
+ return false;
86
+ }
87
+ }));
88
+ this.storeRequests.push(res);
89
+ return res;
90
+ });
91
+ }
92
+ hashUrls(hash) {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ if (hash in this.runContext.requests) {
95
+ return (yield this.runContext.requests[hash])[hash];
96
+ }
97
+ else {
98
+ const scheduledTaskHashesWithoutRequests = this.runContext.scheduledTasks
99
+ .filter((t) => !this.runContext.requests[t.hash])
100
+ .map((t) => t.hash);
101
+ if (scheduledTaskHashesWithoutRequests.indexOf(hash) === -1) {
102
+ scheduledTaskHashesWithoutRequests.push(hash);
103
+ }
104
+ const request = this.api.startRun(environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_ID, scheduledTaskHashesWithoutRequests);
105
+ scheduledTaskHashesWithoutRequests.forEach((taskHash) => {
106
+ this.runContext.requests[taskHash] = request;
107
+ });
108
+ return (yield request)[hash];
109
+ }
110
+ });
111
+ }
112
+ waitForStoreRequestsToComplete() {
113
+ return Promise.all(this.storeRequests).then((r) => r.reduce((a, b) => a && b, true));
114
+ }
115
+ }
116
+ exports.CloudRemoteCache = CloudRemoteCache;
117
+ //# sourceMappingURL=cloud-remote-cache.js.map
@@ -1 +1,167 @@
1
- const a3_0x90b6=['devDependencies','axiosException','message','then','recordMetric','status','RunEnd\x20duration','data','value','startRun','throw','unknown','nxCloudVersion','assign','defineProperty','Nx\x20Cloud:\x20Unknown\x20Error\x20Occurred','apply','messages','package.json','RunStart\x20duration','axiosMultipleTries','stringify','post','api','terminalOutput','apiError','defaults','success','string','../../../utilities/metric-logger','getRunGroup','endRun','mapRespToPerfEntry','../../../utilities/axios','stack','next','Run\x20completion\x20responded\x20with\x20`undefined`.','gzip','apiAxiosInstance','...','createReqBody','from','CloudRunApi','RUNNER_FAILURE_PERF_ENTRY','__awaiter','Invalid\x20end\x20run\x20response','createApiAxiosInstance','../../../utilities/nx-imports','@nrwl/nx-cloud','slice','response','/nx-cloud/runs/start','runUrl','RunEnd.\x20Completed\x20tasks','Stack\x20Trace:','note','zlib','parse','length','map','Run\x20Details:','Invalid\x20end\x20run\x20response:\x20','application/octet-stream','/nx-cloud/runs/end','urls','runContext','Invalid\x20Nx\x20Cloud\x20response:\x20','createMetricRecorder','machineInfo','util','VERBOSE_LOGGING','headers','error'];(function(_0x5ebd3c,_0x90b683){const _0x4266f8=function(_0x2c5836){while(--_0x2c5836){_0x5ebd3c['push'](_0x5ebd3c['shift']());}};_0x4266f8(++_0x90b683);}(a3_0x90b6,0x1f2));const a3_0x4266=function(_0x5ebd3c,_0x90b683){_0x5ebd3c=_0x5ebd3c-0x0;let _0x4266f8=a3_0x90b6[_0x5ebd3c];return _0x4266f8;};'use strict';var __awaiter=this&&this[a3_0x4266('0x39')]||function(_0xbb0b9,_0x2beaf6,_0x27c278,_0x5ec4af){function _0x2d7c5e(_0x1947f1){return _0x1947f1 instanceof _0x27c278?_0x1947f1:new _0x27c278(function(_0x56d7c6){_0x56d7c6(_0x1947f1);});}return new(_0x27c278||(_0x27c278=Promise))(function(_0x30f71e,_0x113088){function _0xe392e1(_0x2c36ef){try{_0xe2d5d5(_0x5ec4af[a3_0x4266('0x30')](_0x2c36ef));}catch(_0x2e1b61){_0x113088(_0x2e1b61);}}function _0x61c7ba(_0x2f5bc2){try{_0xe2d5d5(_0x5ec4af[a3_0x4266('0x17')](_0x2f5bc2));}catch(_0x4f39d8){_0x113088(_0x4f39d8);}}function _0xe2d5d5(_0x2b3eb6){_0x2b3eb6['done']?_0x30f71e(_0x2b3eb6[a3_0x4266('0x15')]):_0x2d7c5e(_0x2b3eb6['value'])[a3_0x4266('0x10')](_0xe392e1,_0x61c7ba);}_0xe2d5d5((_0x5ec4af=_0x5ec4af[a3_0x4266('0x1d')](_0xbb0b9,_0x2beaf6||[]))[a3_0x4266('0x30')]());});};Object[a3_0x4266('0x1b')](exports,'__esModule',{'value':!![]});exports['CloudRunApi']=void 0x0;const axios_1=require(a3_0x4266('0x2e'));const environment_1=require('../../../utilities/environment');const fs_1=require('fs');const zlib_1=require(a3_0x4266('0x45'));const util_1=require(a3_0x4266('0x9'));const metric_logger_1=require(a3_0x4266('0x2a'));const {output}=require(a3_0x4266('0x3c'));class CloudRunApi{constructor(_0xcdee2d,_0x289dd4,_0x2d2ce4,_0x1b9a20){this[a3_0x4266('0x1e')]=_0xcdee2d;this[a3_0x4266('0x5')]=_0x289dd4;this[a3_0x4266('0x8')]=_0x1b9a20;this[a3_0x4266('0x33')]=(0x0,axios_1[a3_0x4266('0x3b')])(_0x2d2ce4);}[a3_0x4266('0x16')](_0x1b0de6,_0x4f5142){var _0x2479d9;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x15d08b=(0x0,metric_logger_1[a3_0x4266('0x7')])(a3_0x4266('0x16'));try{const _0x2c71a6={'meta':{'nxCloudVersion':this[a3_0x4266('0x19')]()},'branch':(0x0,environment_1['getBranch'])(),'runGroup':(0x0,environment_1[a3_0x4266('0x2b')])(),'distributedExecutionId':_0x1b0de6,'hashes':_0x4f5142};if(environment_1['VERBOSE_LOGGING']){output['note']({'title':'RunStart','bodyLines':['\x0a'+JSON[a3_0x4266('0x22')](_0x2c71a6,null,0x2)]});}const _0x1b21e6=yield(0x0,axios_1['printDuration'])(a3_0x4266('0x20'),()=>(0x0,axios_1[a3_0x4266('0x21')])(()=>this[a3_0x4266('0x33')][a3_0x4266('0x23')](a3_0x4266('0x40'),_0x2c71a6)));_0x15d08b[a3_0x4266('0x11')]((0x0,metric_logger_1[a3_0x4266('0x2d')])(_0x1b21e6));if(_0x1b21e6[a3_0x4266('0x14')]&&_0x1b21e6[a3_0x4266('0x14')][a3_0x4266('0xf')]){this['messages'][a3_0x4266('0xf')]=_0x1b21e6[a3_0x4266('0x14')][a3_0x4266('0xf')];}if(!_0x1b21e6['data']||!_0x1b21e6[a3_0x4266('0x14')][a3_0x4266('0x4')]){this[a3_0x4266('0x1e')][a3_0x4266('0x26')]=a3_0x4266('0x6')+JSON[a3_0x4266('0x22')](_0x1b21e6['data']);return{};}return _0x1b21e6[a3_0x4266('0x14')]['urls'];}catch(_0x29ca08){_0x15d08b[a3_0x4266('0x11')](((_0x2479d9=_0x29ca08===null||_0x29ca08===void 0x0?void 0x0:_0x29ca08['axiosException'])===null||_0x2479d9===void 0x0?void 0x0:_0x2479d9[a3_0x4266('0x3f')])?(0x0,metric_logger_1[a3_0x4266('0x2d')])(_0x29ca08[a3_0x4266('0xe')]['response']):metric_logger_1[a3_0x4266('0x38')]);this[a3_0x4266('0x1e')][a3_0x4266('0x26')]=this[a3_0x4266('0x1e')]['extractErrorMessage'](_0x29ca08,a3_0x4266('0x24'));return{};}});}[a3_0x4266('0x35')](_0x1b9218,_0x5ef53b,_0x2dcb2e){const _0x5c5589={'meta':{'nxCloudVersion':this[a3_0x4266('0x19')]()},'tasks':_0x5ef53b,'run':_0x1b9218,'linkId':_0x2dcb2e,'machineInfo':this[a3_0x4266('0x8')]};return JSON[a3_0x4266('0x22')](_0x5c5589);}[a3_0x4266('0x2c')](_0xecded2,_0x4af0cf,_0x28dd4d){var _0x44ee79,_0x6c7fd6;return __awaiter(this,void 0x0,void 0x0,function*(){if(this[a3_0x4266('0x1e')][a3_0x4266('0x26')])return![];let _0x4e8228=this[a3_0x4266('0x35')](_0xecded2,_0x4af0cf,_0x28dd4d);if(_0x4e8228[a3_0x4266('0x47')]>0x14*0x3e8*0x3e8){_0x4e8228=this['createReqBody'](_0xecded2,_0x4af0cf['map'](_0x1c3d6b=>Object[a3_0x4266('0x1a')](Object[a3_0x4266('0x1a')]({},_0x1c3d6b),{'hashDetails':undefined})));}const _0x1e3a1c=Buffer[a3_0x4266('0x36')](_0x4e8228);const _0x3640cc=yield(0x0,util_1['promisify'])(zlib_1[a3_0x4266('0x32')])(_0x1e3a1c);const _0x2b371f=(0x0,metric_logger_1[a3_0x4266('0x7')])(a3_0x4266('0x2c'));try{if(environment_1[a3_0x4266('0xa')]){const _0x563a8c=_0x4af0cf[a3_0x4266('0x48')](_0x16bb70=>{return Object[a3_0x4266('0x1a')](Object[a3_0x4266('0x1a')]({},_0x16bb70),{'terminalOutput':_0x16bb70[a3_0x4266('0x25')]?_0x16bb70['terminalOutput'][a3_0x4266('0x3e')](0x0,0x14)+a3_0x4266('0x34'):undefined});});output['note']({'title':a3_0x4266('0x42'),'bodyLines':['\x0a'+JSON[a3_0x4266('0x22')](_0x563a8c,null,0x2)]});}const _0x2bb891=yield(0x0,axios_1['printDuration'])(a3_0x4266('0x13'),()=>(0x0,axios_1[a3_0x4266('0x21')])(()=>this['apiAxiosInstance'][a3_0x4266('0x23')](a3_0x4266('0x3'),_0x3640cc,{'headers':Object[a3_0x4266('0x1a')](Object[a3_0x4266('0x1a')]({},this[a3_0x4266('0x33')][a3_0x4266('0x27')][a3_0x4266('0xb')]),{'Content-Encoding':a3_0x4266('0x32'),'Content-Type':a3_0x4266('0x2')})})));if(_0x2bb891){_0x2b371f['recordMetric']((0x0,metric_logger_1['mapRespToPerfEntry'])(_0x2bb891));if(_0x2bb891[a3_0x4266('0x14')]&&_0x2bb891['data'][a3_0x4266('0x41')]&&_0x2bb891[a3_0x4266('0x14')]['status']===a3_0x4266('0x28')){this[a3_0x4266('0x5')][a3_0x4266('0x41')]=_0x2bb891['data'][a3_0x4266('0x41')];return!![];}if(_0x2bb891[a3_0x4266('0x14')]&&_0x2bb891[a3_0x4266('0x14')][a3_0x4266('0x12')]){this[a3_0x4266('0x1e')][a3_0x4266('0x26')]=a3_0x4266('0x1')+JSON[a3_0x4266('0x22')](_0x2bb891[a3_0x4266('0x14')]['message']);}else if(_0x2bb891[a3_0x4266('0x14')]&&typeof _0x2bb891['data']===a3_0x4266('0x29')){if(_0x2bb891['data']!==a3_0x4266('0x28')){this[a3_0x4266('0x1e')][a3_0x4266('0x26')]=a3_0x4266('0x1')+JSON[a3_0x4266('0x22')](_0x2bb891[a3_0x4266('0x14')]);}}else{this[a3_0x4266('0x1e')][a3_0x4266('0x26')]='Invalid\x20end\x20run\x20response:\x20'+JSON[a3_0x4266('0x22')](_0x2bb891[a3_0x4266('0x14')]);}if(environment_1['VERBOSE_LOGGING']){output[a3_0x4266('0x44')]({'title':a3_0x4266('0x3a'),'bodyLines':[JSON[a3_0x4266('0x22')](_0x2bb891[a3_0x4266('0x14')],null,0x2)]});}}else{output[a3_0x4266('0xc')]({'title':a3_0x4266('0x1c'),'bodyLines':[a3_0x4266('0x31'),a3_0x4266('0x0'),JSON[a3_0x4266('0x22')](_0xecded2,null,0x2),a3_0x4266('0x43'),JSON[a3_0x4266('0x22')](new Error()[a3_0x4266('0x2f')],null,0x2)]});}return![];}catch(_0x5361ae){_0x2b371f[a3_0x4266('0x11')](((_0x44ee79=_0x5361ae===null||_0x5361ae===void 0x0?void 0x0:_0x5361ae[a3_0x4266('0xe')])===null||_0x44ee79===void 0x0?void 0x0:_0x44ee79[a3_0x4266('0x3f')])?(0x0,metric_logger_1[a3_0x4266('0x2d')])(_0x5361ae[a3_0x4266('0xe')][a3_0x4266('0x3f')]):metric_logger_1['RUNNER_FAILURE_PERF_ENTRY']);const _0x2bb394=(_0x6c7fd6=_0x5361ae[a3_0x4266('0xe')])!==null&&_0x6c7fd6!==void 0x0?_0x6c7fd6:_0x5361ae;this[a3_0x4266('0x1e')][a3_0x4266('0x26')]=this[a3_0x4266('0x1e')]['extractErrorMessage'](_0x2bb394,'api');return![];}});}['nxCloudVersion'](){try{const _0x281461=JSON[a3_0x4266('0x46')]((0x0,fs_1['readFileSync'])(a3_0x4266('0x1f'))['toString']());return _0x281461[a3_0x4266('0xd')][a3_0x4266('0x3d')];}catch(_0x4071b4){return a3_0x4266('0x18');}}}exports[a3_0x4266('0x37')]=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_0x10af=['length','generateUniqueLinkId','random','defineProperty','__esModule','toLowerCase','ABCDEFGHIJKLMNOPQRSTUVWXYZ','0123456789','floor'];(function(_0x33cf49,_0x10af8b){const _0x9828bd=function(_0x2e4f09){while(--_0x2e4f09){_0x33cf49['push'](_0x33cf49['shift']());}};_0x9828bd(++_0x10af8b);}(a4_0x10af,0x13d));const a4_0x9828=function(_0x33cf49,_0x10af8b){_0x33cf49=_0x33cf49-0x0;let _0x9828bd=a4_0x10af[_0x33cf49];return _0x9828bd;};'use strict';Object[a4_0x9828('0x1')](exports,a4_0x9828('0x2'),{'value':!![]});exports[a4_0x9828('0x8')]=void 0x0;const upper=a4_0x9828('0x4');const digits=a4_0x9828('0x5');const lower=upper[a4_0x9828('0x3')]();const alphanum=upper+lower+digits;function generateUniqueLinkId(){let _0x3181a3='';for(let _0x27f379=0x0;_0x27f379<0xa;++_0x27f379){_0x3181a3+=alphanum[Math[a4_0x9828('0x6')](Math[a4_0x9828('0x0')]()*alphanum[a4_0x9828('0x7')])];}return _0x3181a3;}exports[a4_0x9828('0x8')]=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,80 @@
1
- const a5_0x1e05=['runGroup:\x20','createApiAxiosInstance','runGroup','response','completeRunGroup','apply','axiosMultipleTries','error:\x20','agentName','note','__esModule','then','error','recordMetric','VERBOSE_LOGGING','apiAxiosInstance','dtePollTasks','createMetricRecorder','../../../utilities/metric-logger','throw','completeRunGroupWithError','axiosException','Completed\x20run\x20group\x20with\x20an\x20error','/nx-cloud/executions/tasks','value','Completing\x20run\x20group\x20with\x20an\x20error','next','post','tasks','../../../utilities/nx-imports','DistributedAgentApi','RUNNER_FAILURE_PERF_ENTRY','mapRespToPerfEntry','defineProperty'];(function(_0x7d0624,_0x1e0501){const _0x4c4ac8=function(_0x5c2499){while(--_0x5c2499){_0x7d0624['push'](_0x7d0624['shift']());}};_0x4c4ac8(++_0x1e0501);}(a5_0x1e05,0x84));const a5_0x4c4a=function(_0x7d0624,_0x1e0501){_0x7d0624=_0x7d0624-0x0;let _0x4c4ac8=a5_0x1e05[_0x7d0624];return _0x4c4ac8;};'use strict';var __awaiter=this&&this['__awaiter']||function(_0x462060,_0x2aa9d8,_0x598f12,_0x45c9f3){function _0xf9db1f(_0x4c1a0d){return _0x4c1a0d instanceof _0x598f12?_0x4c1a0d:new _0x598f12(function(_0x427a35){_0x427a35(_0x4c1a0d);});}return new(_0x598f12||(_0x598f12=Promise))(function(_0x50aa45,_0x406fa9){function _0x1075a5(_0x4db932){try{_0x53aff4(_0x45c9f3[a5_0x4c4a('0x1e')](_0x4db932));}catch(_0x207cfe){_0x406fa9(_0x207cfe);}}function _0x1113aa(_0x5e284d){try{_0x53aff4(_0x45c9f3[a5_0x4c4a('0x17')](_0x5e284d));}catch(_0x70c9a7){_0x406fa9(_0x70c9a7);}}function _0x53aff4(_0x3647e7){_0x3647e7['done']?_0x50aa45(_0x3647e7[a5_0x4c4a('0x1c')]):_0xf9db1f(_0x3647e7[a5_0x4c4a('0x1c')])[a5_0x4c4a('0xf')](_0x1075a5,_0x1113aa);}_0x53aff4((_0x45c9f3=_0x45c9f3[a5_0x4c4a('0x9')](_0x462060,_0x2aa9d8||[]))[a5_0x4c4a('0x1e')]());});};Object[a5_0x4c4a('0x3')](exports,a5_0x4c4a('0xe'),{'value':!![]});exports['DistributedAgentApi']=void 0x0;const axios_1=require('../../../utilities/axios');const environment_1=require('../../../utilities/environment');const metric_logger_1=require(a5_0x4c4a('0x16'));const {output}=require(a5_0x4c4a('0x21'));class DistributedAgentApi{constructor(_0x487178,_0x44973d,_0x2aca11){this['runGroup']=_0x44973d;this['agentName']=_0x2aca11;this['apiAxiosInstance']=(0x0,axios_1[a5_0x4c4a('0x5')])(_0x487178);}[a5_0x4c4a('0x20')](_0x2b0556,_0x1826ac,_0x130426,_0x1f227d){var _0x5c59f8;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x1789a5=(0x0,metric_logger_1[a5_0x4c4a('0x15')])(a5_0x4c4a('0x14'));try{const _0xb6ec7=yield(0x0,axios_1[a5_0x4c4a('0xa')])(()=>this['apiAxiosInstance'][a5_0x4c4a('0x1f')](a5_0x4c4a('0x1b'),{'runGroup':this[a5_0x4c4a('0x6')],'agentName':this[a5_0x4c4a('0xc')],'executionId':_0x2b0556,'statusCode':_0x1826ac,'completedTasks':_0x130426,'targets':_0x1f227d}));_0x1789a5[a5_0x4c4a('0x11')]((0x0,metric_logger_1['mapRespToPerfEntry'])(_0xb6ec7));return _0xb6ec7['data'];}catch(_0x1eafb9){_0x1789a5[a5_0x4c4a('0x11')](((_0x5c59f8=_0x1eafb9===null||_0x1eafb9===void 0x0?void 0x0:_0x1eafb9[a5_0x4c4a('0x19')])===null||_0x5c59f8===void 0x0?void 0x0:_0x5c59f8['response'])?(0x0,metric_logger_1['mapRespToPerfEntry'])(_0x1eafb9[a5_0x4c4a('0x19')]['response']):metric_logger_1[a5_0x4c4a('0x1')]);throw _0x1eafb9;}});}[a5_0x4c4a('0x18')](_0x31ffc8){var _0xb1ce6;return __awaiter(this,void 0x0,void 0x0,function*(){if(environment_1[a5_0x4c4a('0x12')]){output[a5_0x4c4a('0xd')]({'title':a5_0x4c4a('0x1d'),'bodyLines':[a5_0x4c4a('0x4')+this[a5_0x4c4a('0x6')],a5_0x4c4a('0xb')+_0x31ffc8]});}const _0x452460=(0x0,metric_logger_1[a5_0x4c4a('0x15')])(a5_0x4c4a('0x8'));try{const _0x514d43=yield(0x0,axios_1[a5_0x4c4a('0xa')])(()=>this[a5_0x4c4a('0x13')][a5_0x4c4a('0x1f')]('/nx-cloud/executions/complete-run-group',{'runGroup':this['runGroup'],'agentName':this[a5_0x4c4a('0xc')],'criticalErrorMessage':_0x31ffc8}));if(environment_1[a5_0x4c4a('0x12')]){output[a5_0x4c4a('0xd')]({'title':a5_0x4c4a('0x1a')});}_0x452460[a5_0x4c4a('0x11')]((0x0,metric_logger_1['mapRespToPerfEntry'])(_0x514d43));}catch(_0x3bc2fe){_0x452460[a5_0x4c4a('0x11')](((_0xb1ce6=_0x3bc2fe===null||_0x3bc2fe===void 0x0?void 0x0:_0x3bc2fe[a5_0x4c4a('0x19')])===null||_0xb1ce6===void 0x0?void 0x0:_0xb1ce6[a5_0x4c4a('0x7')])?(0x0,metric_logger_1[a5_0x4c4a('0x2')])(_0x3bc2fe[a5_0x4c4a('0x19')][a5_0x4c4a('0x7')]):metric_logger_1[a5_0x4c4a('0x1')]);console[a5_0x4c4a('0x10')](_0x3bc2fe);}});}}exports[a5_0x4c4a('0x0')]=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, targets) {
24
+ var _a;
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const recorder = (0, metric_logger_1.createMetricRecorder)('dtePollTasks');
27
+ try {
28
+ const res = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/tasks', {
29
+ runGroup: this.runGroup,
30
+ agentName: this.agentName,
31
+ executionId,
32
+ statusCode,
33
+ completedTasks,
34
+ targets,
35
+ }));
36
+ recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(res));
37
+ return res.data;
38
+ }
39
+ catch (e) {
40
+ recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
41
+ ? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
42
+ : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
43
+ throw e;
44
+ }
45
+ });
46
+ }
47
+ completeRunGroupWithError(error) {
48
+ var _a;
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ if (environment_1.VERBOSE_LOGGING) {
51
+ output.note({
52
+ title: 'Completing run group with an error',
53
+ bodyLines: [`runGroup: ${this.runGroup}`, `error: ${error}`],
54
+ });
55
+ }
56
+ const recorder = (0, metric_logger_1.createMetricRecorder)('completeRunGroup');
57
+ try {
58
+ const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/complete-run-group', {
59
+ runGroup: this.runGroup,
60
+ agentName: this.agentName,
61
+ criticalErrorMessage: error,
62
+ }));
63
+ if (environment_1.VERBOSE_LOGGING) {
64
+ output.note({
65
+ title: 'Completed run group with an error',
66
+ });
67
+ }
68
+ recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
69
+ }
70
+ catch (e) {
71
+ recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
72
+ ? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
73
+ : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
74
+ console.error(e);
75
+ }
76
+ });
77
+ }
78
+ }
79
+ exports.DistributedAgentApi = DistributedAgentApi;
80
+ //# sourceMappingURL=distributed-agent.api.js.map
@@ -1 +1,154 @@
1
- const a6_0x1aa3=['value','../../error/print-run-group-error','completed','NO_MESSAGES_TIMEOUT','Fetching\x20tasks...','strip-json-comments','retryDuring','maxParallel:\x20','printCacheableTargetsError','includes','target','join','status','find','VERBOSE_LOGGING','executionId','RUN_GROUP_COMPLETED','reset','map','CIRCLE_JOB','No\x20new\x20messages\x20received\x20after\x20','../../../utilities/create-unchanged-value-timeout','length','NO_FURTHER_TASKS_TO_RUN','/lockfiles','CIRCLE_STAGE','../../../utilities/environment','printInvalidRunnerError','inherit','__esModule','number\x20of\x20tasks:\x20','options','Critical\x20Error\x20in\x20Agent:\x20\x22','End\x20all\x20currently\x20running\x20agents,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22,\x20and\x20try\x20again.','Error:','message','note','writeFileSync','API\x20Response','params','tasksRunnerOptions','__awaiter','retryDuring:\x20','forEach','mkdirSync','toString','configuration','then','split','startAgent','../../error/print-invalid-runner-error','getRunGroup','warn','npx\x20nx\x20run-many\x20--target=','tasks','getTime','readFileSync','@nrwl/nx-cloud','getNxCacheDirectory','completeRunGroupWithError','\x20--projects=','SIGTERM','trim','CIRCLECI','Waiter','execSync','taskId','runner','push','ignore','parse','DistributedAgentApi','submitRunMetrics','done','true','Duplicate\x20Agent\x20ID\x20Detected','catch','maxParallel','apply','Command\x20execution\x20failed\x20(distributed\x20task\x20execution:\x20','defineProperty','floor',').\x20Tasks\x20hashes\x20haven\x27t\x20been\x20recorded.','exit','Agent\x20','error:\x20','assign','executionId:\x20','existsSync','throw','argv','SIGINT','completedTasks','cacheableOperations','We\x20have\x20detected\x20another\x20agent\x20with\x20this\x20ID\x20running\x20in\x20this\x20workspace.\x20This\x20should\x20not\x20happen.','criticalErrorMessage','wait','error','env','filter','../../error/print-cacheable-targets-error','Other\x20Nx\x20Cloud\x20Agents\x20Detected','status:\x20','next','Waiting...','./distributed-agent.api','unlinkSync','targets','We\x20have\x20detected\x20other\x20agents\x20running\x20in\x20this\x20workspace.\x20This\x20can\x20cause\x20unexpected\x20behavior.','This\x20can\x20also\x20be\x20a\x20false\x20positive\x20caused\x20by\x20agents\x20that\x20did\x20not\x20shut\x20down\x20correctly.','.lock','../../../utilities/waiter','projectName','../../../utilities/nx-imports','NX_AGENT_NAME'];(function(_0x416217,_0x1aa3e9){const _0x365e13=function(_0x171e7a){while(--_0x171e7a){_0x416217['push'](_0x416217['shift']());}};_0x365e13(++_0x1aa3e9);}(a6_0x1aa3,0x176));const a6_0x365e=function(_0x416217,_0x1aa3e9){_0x416217=_0x416217-0x0;let _0x365e13=a6_0x1aa3[_0x416217];return _0x365e13;};'use strict';var __awaiter=this&&this[a6_0x365e('0xc')]||function(_0x23c3b0,_0x229aad,_0x31a380,_0x550722){function _0x9a692(_0x2db42b){return _0x2db42b instanceof _0x31a380?_0x2db42b:new _0x31a380(function(_0x346eee){_0x346eee(_0x2db42b);});}return new(_0x31a380||(_0x31a380=Promise))(function(_0x4d80b6,_0x536e3e){function _0x57d0c9(_0x1b4649){try{_0x3d12da(_0x550722['next'](_0x1b4649));}catch(_0x2d323b){_0x536e3e(_0x2d323b);}}function _0x2d2134(_0x333d12){try{_0x3d12da(_0x550722[a6_0x365e('0x3c')](_0x333d12));}catch(_0x16c77e){_0x536e3e(_0x16c77e);}}function _0x3d12da(_0xf33706){_0xf33706[a6_0x365e('0x2c')]?_0x4d80b6(_0xf33706[a6_0x365e('0x56')]):_0x9a692(_0xf33706[a6_0x365e('0x56')])[a6_0x365e('0x12')](_0x57d0c9,_0x2d2134);}_0x3d12da((_0x550722=_0x550722[a6_0x365e('0x31')](_0x23c3b0,_0x229aad||[]))[a6_0x365e('0x4a')]());});};Object[a6_0x365e('0x33')](exports,a6_0x365e('0x0'),{'value':!![]});exports['startAgent']=void 0x0;const child_process_1=require('child_process');const fs_1=require('fs');const stripJsonComments=require(a6_0x365e('0x5b'));const yargsParser=require('yargs-parser');const create_unchanged_value_timeout_1=require(a6_0x365e('0x6b'));const environment_1=require(a6_0x365e('0x70'));const metric_logger_1=require('../../../utilities/metric-logger');const waiter_1=require(a6_0x365e('0x52'));const print_cacheable_targets_error_1=require(a6_0x365e('0x47'));const print_invalid_runner_error_1=require(a6_0x365e('0x15'));const print_run_group_error_1=require(a6_0x365e('0x57'));const distributed_agent_api_1=require(a6_0x365e('0x4c'));const {output,workspaceRoot}=require(a6_0x365e('0x54'));const args=yargsParser(process[a6_0x365e('0x3d')],{'array':[a6_0x365e('0x4e')],'default':{}});if(args['targets']&&args[a6_0x365e('0x4e')][a6_0x365e('0x6c')]===0x1){args['targets']=args[a6_0x365e('0x4e')][0x0][a6_0x365e('0x13')](',')[a6_0x365e('0x68')](_0x3f29ef=>_0x3f29ef[a6_0x365e('0x21')]());}function executeTasks(_0x47bef3,_0x32b766){return __awaiter(this,void 0x0,void 0x0,function*(){let _0x345e83=0x0;let _0x45cd5e=null;const _0x4d1718=(0x0,create_unchanged_value_timeout_1['createUnchangedValueTimeout'])({'title':a6_0x365e('0x6a')+environment_1[a6_0x365e('0x59')]/0x3e8+'\x20seconds','timeout':environment_1[a6_0x365e('0x59')]});const _0x19172e=new waiter_1[(a6_0x365e('0x23'))]();let _0x6ad5e9=[];const _0x780762=new Date();let _0x1db747=![];while(!![]){if(environment_1['VERBOSE_LOGGING']){output[a6_0x365e('0x7')]({'title':a6_0x365e('0x5a')});}_0x45cd5e=yield _0x32b766['tasks'](_0x45cd5e?_0x45cd5e['executionId']:null,_0x345e83,_0x6ad5e9,args[a6_0x365e('0x4e')]);if(environment_1[a6_0x365e('0x64')]){output['note']({'title':a6_0x365e('0x9'),'bodyLines':['completed:\x20'+_0x45cd5e[a6_0x365e('0x58')],a6_0x365e('0x49')+_0x45cd5e[a6_0x365e('0x62')],a6_0x365e('0xd')+_0x45cd5e['retryDuring'],a6_0x365e('0x3a')+_0x45cd5e[a6_0x365e('0x65')],a6_0x365e('0x1')+_0x45cd5e[a6_0x365e('0x19')][a6_0x365e('0x6c')],a6_0x365e('0x38')+_0x45cd5e['criticalErrorMessage'],a6_0x365e('0x5d')+_0x45cd5e[a6_0x365e('0x30')]]});}if(_0x45cd5e[a6_0x365e('0x42')]){output[a6_0x365e('0x44')]({'title':'Distributed\x20Execution\x20Terminated','bodyLines':[a6_0x365e('0x5'),_0x45cd5e[a6_0x365e('0x42')]]});process[a6_0x365e('0x36')](0x0);}if((_0x45cd5e===null||_0x45cd5e===void 0x0?void 0x0:_0x45cd5e['retryDuring'])&&(_0x45cd5e===null||_0x45cd5e===void 0x0?void 0x0:_0x45cd5e[a6_0x365e('0x5c')])!==0x0&&!_0x1db747&&new Date()[a6_0x365e('0x1a')]()-_0x780762[a6_0x365e('0x1a')]()>_0x45cd5e[a6_0x365e('0x5c')]){yield _0x19172e[a6_0x365e('0x43')]();continue;}if((_0x45cd5e===null||_0x45cd5e===void 0x0?void 0x0:_0x45cd5e['status'])!==undefined){if(_0x45cd5e[a6_0x365e('0x62')]===a6_0x365e('0x66')||_0x45cd5e['status']===a6_0x365e('0x6d')){return;}}else if(_0x45cd5e['completed']){return;}_0x4d1718(_0x45cd5e['tasks'][a6_0x365e('0x68')](_0x4fd68f=>_0x4fd68f[a6_0x365e('0x25')])['join'](''));if(!_0x45cd5e['executionId']){if(environment_1[a6_0x365e('0x64')]){output[a6_0x365e('0x7')]({'title':a6_0x365e('0x4b')});}yield _0x19172e[a6_0x365e('0x43')]();_0x345e83=0x0;_0x6ad5e9=[];continue;}_0x19172e[a6_0x365e('0x67')]();_0x1db747=!![];const _0x2aff9c=invokeTasksUsingRunMany(_0x47bef3,_0x45cd5e[a6_0x365e('0x65')],_0x45cd5e[a6_0x365e('0x19')],_0x45cd5e[a6_0x365e('0x30')]);_0x345e83=_0x2aff9c['completedStatusCode'];_0x6ad5e9=_0x2aff9c[a6_0x365e('0x3f')];}});}function readCompletedTasks(_0x1aef13,_0x536691){const _0x220018=a6_0x365e('0x32')+_0x536691+a6_0x365e('0x35');let _0x16e65e;try{const _0x56dc41=(0x0,environment_1['getNxCacheDirectory'])(_0x1aef13);const _0x412d1d=_0x56dc41+'/tasks-hashes-'+_0x536691;_0x16e65e=JSON[a6_0x365e('0x29')]((0x0,fs_1[a6_0x365e('0x1b')])(_0x412d1d)[a6_0x365e('0x10')]());(0x0,fs_1[a6_0x365e('0x4d')])(_0x412d1d);}catch(_0xd228a9){throw new Error(_0x220018);}if(_0x16e65e[a6_0x365e('0x6c')]==0x0){throw new Error(_0x220018);}return _0x16e65e;}function invokeTasksUsingRunMany(_0x187aad,_0x58c44c,_0x54bdec,_0x1ccc5c){let _0x4975f8=0x0;const _0x1b6de5=[];for(const _0x5588d6 of groupByTarget(_0x54bdec)){const _0x2ff291=_0x5588d6[a6_0x365e('0x11')]?'--configuration='+_0x5588d6['configuration']:'';const _0x5328d5=_0x1ccc5c>0x1?'\x20--parallel\x20--max-parallel='+_0x1ccc5c:'';const _0x4fce29=a6_0x365e('0x18')+_0x5588d6[a6_0x365e('0x60')]+'\x20'+_0x2ff291+a6_0x365e('0x1f')+_0x5588d6['projects'][a6_0x365e('0x61')](',')+'\x20'+_0x5588d6[a6_0x365e('0xa')]+_0x5328d5;if(environment_1['VERBOSE_LOGGING']){output['note']({'title':'Executing:\x20\x27'+_0x4fce29+'\x27'});}try{(0x0,child_process_1[a6_0x365e('0x24')])(_0x4fce29,{'stdio':[a6_0x365e('0x28'),a6_0x365e('0x72'),a6_0x365e('0x72')],'env':Object[a6_0x365e('0x39')](Object[a6_0x365e('0x39')]({},process['env']),{'NX_CACHE_FAILURES':a6_0x365e('0x2d'),'NX_CLOUD_DISTRIBUTED_EXECUTION_ID':_0x58c44c,'NX_STREAM_OUTPUT':a6_0x365e('0x2d'),'NX_PREFIX_OUTPUT':a6_0x365e('0x2d')})});_0x1b6de5['push'](...readCompletedTasks(_0x187aad,_0x58c44c));}catch(_0x2b66d2){if(_0x2b66d2['status']===environment_1['DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE']){throw _0x2b66d2;}else{_0x4975f8=0x1;_0x1b6de5['push'](...readCompletedTasks(_0x187aad,_0x58c44c));}}}return{'completedStatusCode':_0x4975f8,'completedTasks':_0x1b6de5};}function groupByTarget(_0x3cb56a){const _0xda7bae=[];_0x3cb56a[a6_0x365e('0xe')](_0x3dc6ce=>{const _0x582691=_0xda7bae[a6_0x365e('0x63')](_0x539fc8=>_0x539fc8[a6_0x365e('0x60')]===_0x3dc6ce[a6_0x365e('0x60')]&&_0x539fc8[a6_0x365e('0x11')]===_0x3dc6ce[a6_0x365e('0x11')]);if(_0x582691){_0x582691['projects'][a6_0x365e('0x27')](_0x3dc6ce['projectName']);}else{_0xda7bae[a6_0x365e('0x27')]({'target':_0x3dc6ce['target'],'projects':[_0x3dc6ce[a6_0x365e('0x53')]],'params':_0x3dc6ce['params'],'configuration':_0x3dc6ce[a6_0x365e('0x11')]});}});return _0xda7bae;}function getAgentName(){if(process[a6_0x365e('0x45')][a6_0x365e('0x55')]!==undefined){return process['env'][a6_0x365e('0x55')];}else if(process[a6_0x365e('0x45')][a6_0x365e('0x22')]!==undefined&&process[a6_0x365e('0x45')][a6_0x365e('0x6f')]){return process['env']['CIRCLE_STAGE'];}else if(process[a6_0x365e('0x45')][a6_0x365e('0x22')]!==undefined&&process[a6_0x365e('0x45')]['CIRCLE_JOB']){return process['env'][a6_0x365e('0x69')];}else{return a6_0x365e('0x37')+Math[a6_0x365e('0x34')](Math['random']()*0x186a0);}}function createAgentLockfileAndSetUpListeners(_0x8f5b,_0x5adaa3,_0x451eba){const _0x5b29b9=(0x0,environment_1[a6_0x365e('0x1d')])(_0x5adaa3);const _0x51a3e4=_0x5b29b9+a6_0x365e('0x6e');const _0x4a6040=_0x51a3e4+'/'+_0x451eba+a6_0x365e('0x51');if(!(0x0,fs_1[a6_0x365e('0x3b')])(_0x51a3e4)){(0x0,fs_1[a6_0x365e('0xf')])(_0x51a3e4,{'recursive':!![]});}const _0x55ac89=(0x0,fs_1['readdirSync'])(_0x51a3e4);if(_0x55ac89[a6_0x365e('0x6c')]){if(_0x55ac89[a6_0x365e('0x5f')](_0x451eba+a6_0x365e('0x51'))){output[a6_0x365e('0x44')]({'title':a6_0x365e('0x2e'),'bodyLines':[a6_0x365e('0x41'),'',a6_0x365e('0x4')]});process['exit'](0x1);}output[a6_0x365e('0x17')]({'title':a6_0x365e('0x48'),'bodyLines':[a6_0x365e('0x4f'),'',a6_0x365e('0x50'),'If\x20you\x20believe\x20this\x20is\x20the\x20case,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22.']});}(0x0,fs_1[a6_0x365e('0x8')])(_0x4a6040,'');process['on']('exit',_0x19dc26=>{cleanupAgentLockfile(_0x4a6040,_0x19dc26);});process['on'](a6_0x365e('0x20'),()=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x8f5b['completeRunGroupWithError']('Agent\x20was\x20terminated\x20via\x20SIGTERM');cleanupAgentLockfile(_0x4a6040,0x1);}));process['on'](a6_0x365e('0x3e'),()=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x8f5b['completeRunGroupWithError']('Agent\x20was\x20terminated\x20via\x20SIGINT');cleanupAgentLockfile(_0x4a6040,0x1);}));}function cleanupAgentLockfile(_0x2ee76c,_0x157954){if((0x0,fs_1[a6_0x365e('0x3b')])(_0x2ee76c)){(0x0,fs_1[a6_0x365e('0x4d')])(_0x2ee76c);process[a6_0x365e('0x36')](_0x157954);}}function startAgent(){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x70d990=(0x0,environment_1[a6_0x365e('0x16')])();if(!_0x70d990){(0x0,print_run_group_error_1['printRunGroupError'])();return process[a6_0x365e('0x36')](0x1);}if(args[a6_0x365e('0x4e')]&&args[a6_0x365e('0x4e')][a6_0x365e('0x6c')]){output[a6_0x365e('0x7')]({'title':'Starting\x20an\x20agent\x20for\x20running\x20Nx\x20target(s)\x20['+args[a6_0x365e('0x4e')][a6_0x365e('0x61')](',\x20')+']'});}else{output['note']({'title':'Starting\x20an\x20agent\x20for\x20running\x20Nx\x20tasks'});}const _0x53fcbb=JSON[a6_0x365e('0x29')](stripJsonComments((0x0,fs_1[a6_0x365e('0x1b')])(workspaceRoot+'/nx.json')[a6_0x365e('0x10')]()))[a6_0x365e('0xb')]['default'];if(_0x53fcbb[a6_0x365e('0x26')]!==a6_0x365e('0x1c')){(0x0,print_invalid_runner_error_1[a6_0x365e('0x71')])();return process['exit'](0x1);}const _0x57e695=_0x53fcbb[a6_0x365e('0x2')];if(args['targets']&&args[a6_0x365e('0x4e')]['some'](_0x5f45c2=>{var _0x52e453;return!((_0x52e453=_0x57e695[a6_0x365e('0x40')])===null||_0x52e453===void 0x0?void 0x0:_0x52e453[a6_0x365e('0x5f')](_0x5f45c2));})){const _0x4939fc=args[a6_0x365e('0x4e')][a6_0x365e('0x46')](_0x2470de=>{var _0x26e400;return!((_0x26e400=_0x57e695[a6_0x365e('0x40')])===null||_0x26e400===void 0x0?void 0x0:_0x26e400['includes'](_0x2470de));});(0x0,print_cacheable_targets_error_1[a6_0x365e('0x5e')])(_0x4939fc);return process[a6_0x365e('0x36')](0x1);}const _0xad1e7d=getAgentName();const _0x4995b4=new distributed_agent_api_1[(a6_0x365e('0x2a'))](_0x57e695,_0x70d990,_0xad1e7d);createAgentLockfileAndSetUpListeners(_0x4995b4,_0x57e695,_0xad1e7d);return executeTasks(_0x57e695,_0x4995b4)[a6_0x365e('0x12')](_0x26a698=>__awaiter(this,void 0x0,void 0x0,function*(){yield(0x0,metric_logger_1[a6_0x365e('0x2b')])(_0x57e695);return _0x26a698;}))[a6_0x365e('0x2f')](_0x4e2d6e=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x4995b4[a6_0x365e('0x1e')](a6_0x365e('0x3')+_0x4e2d6e[a6_0x365e('0x6')]+'\x22');throw _0x4e2d6e;}));});}exports[a6_0x365e('0x14')]=startAgent;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.startAgent = void 0;
13
+ const fs_1 = require("fs");
14
+ const stripJsonComments = require("strip-json-comments");
15
+ const yargsParser = require("yargs-parser");
16
+ const environment_1 = require("../../../utilities/environment");
17
+ const metric_logger_1 = require("../../../utilities/metric-logger");
18
+ const print_cacheable_targets_error_1 = require("../../error/print-cacheable-targets-error");
19
+ const print_invalid_runner_error_1 = require("../../error/print-invalid-runner-error");
20
+ const print_run_group_error_1 = require("../../error/print-run-group-error");
21
+ const distributed_agent_api_1 = require("./distributed-agent.api");
22
+ const execute_tasks_1 = require("./execute-tasks");
23
+ const dte_artifact_storage_1 = require("../../../utilities/dte-artifact-storage");
24
+ const file_storage_1 = require("../../file-storage/file-storage");
25
+ const e2e_encryption_1 = require("../../file-storage/e2e-encryption");
26
+ const error_reporter_api_1 = require("../../api/error-reporter.api");
27
+ const invoke_tasks_using_run_many_1 = require("./invoke-tasks-using-run-many");
28
+ const invoke_tasks_using_nx_imperative_api_1 = require("./invoke-tasks-using-nx-imperative-api");
29
+ const { output, initTasksRunner, workspaceRoot, } = require('../../../utilities/nx-imports');
30
+ const args = yargsParser(process.argv, {
31
+ array: ['targets'],
32
+ default: {},
33
+ });
34
+ // just in case someone passes the args with commas
35
+ // cf. https://github.com/yargs/yargs/issues/846
36
+ if (args.targets && args.targets.length === 1) {
37
+ args.targets = args.targets[0].split(',').map((x) => x.trim());
38
+ }
39
+ function startAgent() {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const runGroup = (0, environment_1.getRunGroup)();
42
+ if (!runGroup) {
43
+ (0, print_run_group_error_1.printRunGroupError)();
44
+ return process.exit(1);
45
+ }
46
+ if (args.targets && args.targets.length) {
47
+ output.note({
48
+ title: `Starting an agent for running Nx target(s) [${args.targets.join(', ')}]`,
49
+ });
50
+ }
51
+ else {
52
+ output.note({
53
+ title: 'Starting an agent for running Nx tasks',
54
+ });
55
+ }
56
+ const defaultRunnerConfig = JSON.parse(stripJsonComments((0, fs_1.readFileSync)(`${workspaceRoot}/nx.json`).toString())).tasksRunnerOptions.default;
57
+ if (defaultRunnerConfig.runner !== '@nrwl/nx-cloud') {
58
+ (0, print_invalid_runner_error_1.printInvalidRunnerError)();
59
+ return process.exit(1);
60
+ }
61
+ const options = defaultRunnerConfig.options;
62
+ if (args.targets &&
63
+ args.targets.some((target) => { var _a; return !((_a = options.cacheableOperations) === null || _a === void 0 ? void 0 : _a.includes(target)); })) {
64
+ const wrongTargets = args.targets.filter((target) => { var _a; return !((_a = options.cacheableOperations) === null || _a === void 0 ? void 0 : _a.includes(target)); });
65
+ (0, print_cacheable_targets_error_1.printCacheableTargetsError)(wrongTargets);
66
+ return process.exit(1);
67
+ }
68
+ const agentName = getAgentName();
69
+ const api = new distributed_agent_api_1.DistributedAgentApi(options, runGroup, agentName);
70
+ createAgentLockfileAndSetUpListeners(api, options, agentName);
71
+ const encryption = new e2e_encryption_1.E2EEncryption(environment_1.ENCRYPTION_KEY || options.encryptionKey);
72
+ const errorReporter = new error_reporter_api_1.ErrorReporterApi(options);
73
+ const dteArtifactStorage = new dte_artifact_storage_1.DteArtifactStorage(new file_storage_1.FileStorage(encryption, errorReporter, true, false), (0, environment_1.getNxCacheDirectory)(options));
74
+ const invokeTasks = initTasksRunner
75
+ ? yield (0, invoke_tasks_using_nx_imperative_api_1.invokeTasksUsingNxImperativeApi)(options)
76
+ : yield (0, invoke_tasks_using_run_many_1.invokeTasksUsingRunMany)(options);
77
+ return (0, execute_tasks_1.executeTasks)(agentName, api, dteArtifactStorage, invokeTasks, args.targets)
78
+ .then((res) => __awaiter(this, void 0, void 0, function* () {
79
+ yield (0, metric_logger_1.submitRunMetrics)(options);
80
+ return res;
81
+ }))
82
+ .catch((e) => __awaiter(this, void 0, void 0, function* () {
83
+ yield api.completeRunGroupWithError(`Critical Error in Agent: "${e.message}"`);
84
+ throw e;
85
+ }));
86
+ });
87
+ }
88
+ exports.startAgent = startAgent;
89
+ function getAgentName() {
90
+ if (process.env.NX_AGENT_NAME !== undefined) {
91
+ return process.env.NX_AGENT_NAME;
92
+ }
93
+ else if (process.env.CIRCLECI !== undefined && process.env.CIRCLE_STAGE) {
94
+ return process.env.CIRCLE_STAGE;
95
+ }
96
+ else if (process.env.CIRCLECI !== undefined && process.env.CIRCLE_JOB) {
97
+ return process.env.CIRCLE_JOB;
98
+ }
99
+ else {
100
+ return `Agent ${Math.floor(Math.random() * 100000)}`;
101
+ }
102
+ }
103
+ function createAgentLockfileAndSetUpListeners(api, options, agentName) {
104
+ const cacheDirectory = (0, environment_1.getNxCacheDirectory)(options);
105
+ const lockFileDirectory = `${cacheDirectory}/lockfiles`;
106
+ const lockFilePath = `${lockFileDirectory}/${agentName}.lock`;
107
+ if (!(0, fs_1.existsSync)(lockFileDirectory)) {
108
+ (0, fs_1.mkdirSync)(lockFileDirectory, { recursive: true });
109
+ }
110
+ // Check for other agents' lockfiles and warn if exist
111
+ const lockFiles = (0, fs_1.readdirSync)(lockFileDirectory);
112
+ if (lockFiles.length) {
113
+ // Check to make sure the current agent name is not in use (only 1/100000 ^ 2 chance of this)
114
+ if (lockFiles.includes(`${agentName}.lock`)) {
115
+ output.error({
116
+ title: 'Duplicate Agent ID Detected',
117
+ bodyLines: [
118
+ 'We have detected another agent with this ID running in this workspace. This should not happen.',
119
+ '',
120
+ 'End all currently running agents, run "npx nx-cloud clean-up-agents", and try again.',
121
+ ],
122
+ });
123
+ process.exit(1);
124
+ }
125
+ output.warn({
126
+ title: 'Other Nx Cloud Agents Detected',
127
+ bodyLines: [
128
+ 'We have detected other agents running in this workspace. This can cause unexpected behavior.',
129
+ '',
130
+ 'This can also be a false positive caused by agents that did not shut down correctly.',
131
+ 'If you believe this is the case, run "npx nx-cloud clean-up-agents".',
132
+ ],
133
+ });
134
+ }
135
+ (0, fs_1.writeFileSync)(lockFilePath, '');
136
+ process.on('exit', (code) => {
137
+ cleanupAgentLockfile(lockFilePath, code);
138
+ });
139
+ process.on('SIGTERM', () => __awaiter(this, void 0, void 0, function* () {
140
+ yield api.completeRunGroupWithError('Agent was terminated via SIGTERM');
141
+ cleanupAgentLockfile(lockFilePath, 1);
142
+ }));
143
+ process.on('SIGINT', () => __awaiter(this, void 0, void 0, function* () {
144
+ yield api.completeRunGroupWithError('Agent was terminated via SIGINT');
145
+ cleanupAgentLockfile(lockFilePath, 1);
146
+ }));
147
+ }
148
+ function cleanupAgentLockfile(lockFilePath, code) {
149
+ if ((0, fs_1.existsSync)(lockFilePath)) {
150
+ (0, fs_1.unlinkSync)(lockFilePath);
151
+ process.exit(code);
152
+ }
153
+ }
154
+ //# sourceMappingURL=distributed-agent.impl.js.map