@nrwl/nx-cloud 14.4.0 → 14.4.2-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 (31) hide show
  1. package/bin/nx-cloud.js +3 -3
  2. package/bin/nx-cloud.js.map +1 -1
  3. package/lib/core/api/error-reporter.api.js +36 -1
  4. package/lib/core/api/run-group.api.d.ts +1 -1
  5. package/lib/core/api/run-group.api.js +68 -1
  6. package/lib/core/api/run-group.api.js.map +1 -1
  7. package/lib/core/commands/start-ci-run.js +7 -1
  8. package/lib/core/commands/start-ci-run.js.map +1 -1
  9. package/lib/core/models/distributed-agent/tasks-api-response.model.d.ts +1 -0
  10. package/lib/core/runners/cloud-enabled/cloud-enabled-life-cycle.js +156 -1
  11. package/lib/core/runners/cloud-enabled/cloud-enabled.runner.js +201 -1
  12. package/lib/core/runners/cloud-enabled/cloud-enabled.runner.js.map +1 -1
  13. package/lib/core/runners/cloud-enabled/cloud-remote-cache.js +113 -1
  14. package/lib/core/runners/cloud-enabled/cloud-run.api.js +166 -1
  15. package/lib/core/runners/distributed-agent/distributed-agent.api.js +79 -1
  16. package/lib/core/runners/distributed-agent/distributed-agent.impl.js +263 -1
  17. package/lib/core/runners/distributed-agent/distributed-agent.impl.js.map +1 -1
  18. package/lib/core/runners/distributed-execution/distributed-execution.api.js +143 -1
  19. package/lib/core/runners/distributed-execution/distributed-execution.runner.js +220 -1
  20. package/lib/core/runners/distributed-execution/distributed-execution.runner.js.map +1 -1
  21. package/lib/core/runners/distributed-execution/split-task-graph-into-stages.js +37 -1
  22. package/lib/core/runners/distributed-execution/task-graph-creator.js +77 -1
  23. package/lib/utilities/create-unchanged-value-timeout.d.ts +4 -0
  24. package/lib/utilities/{create-no-new-messages-timeout.js → create-unchanged-value-timeout.js} +6 -7
  25. package/lib/utilities/create-unchanged-value-timeout.js.map +1 -0
  26. package/lib/utilities/environment.d.ts +1 -0
  27. package/lib/utilities/environment.js +5 -1
  28. package/lib/utilities/environment.js.map +1 -1
  29. package/package.json +3 -2
  30. package/lib/utilities/create-no-new-messages-timeout.d.ts +0 -1
  31. package/lib/utilities/create-no-new-messages-timeout.js.map +0 -1
@@ -1 +1,263 @@
1
- const a5_0x38e0=['npx\x20nx\x20run-many\x20--target=','default','API\x20Response','Command\x20execution\x20failed\x20(distributed\x20task\x20execution:\x20','\x20--projects=','../../error/print-run-group-error','DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE','true','We\x20have\x20detected\x20another\x20agent\x20with\x20this\x20ID\x20running\x20in\x20this\x20workspace.\x20This\x20should\x20not\x20happen.','getRunGroup','parse','then','wait','End\x20all\x20currently\x20running\x20agents,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22,\x20and\x20try\x20again.','length','value','\x20--parallel\x20--max-parallel=','completed:\x20','projects','CIRCLE_STAGE','CIRCLE_JOB','Starting\x20an\x20agent\x20for\x20running\x20Nx\x20tasks','executionId','apply','cacheDirectory','completedTasks','catch','SIGTERM','./node_modules/.cache/nx','error:\x20','--configuration=','projectName','/tasks-hashes-','maxParallel:\x20','.lock','Critical\x20Error\x20in\x20Agent:\x20\x22','executionId:\x20','params','criticalErrorMessage','target','createNoNewMessagesTimeout','__awaiter','Waiting...','NX_AGENT_NAME','assign','completeRunGroupWithError','done','warn','child_process','tasks','Distributed\x20Execution\x20Terminated','error','floor','CIRCLECI','Executing:\x20\x27','strip-json-comments','Waiter','push','Agent\x20was\x20terminated\x20via\x20SIGTERM','We\x20have\x20detected\x20other\x20agents\x20running\x20in\x20this\x20workspace.\x20This\x20can\x20cause\x20unexpected\x20behavior.','note','Other\x20Nx\x20Cloud\x20Agents\x20Detected','random','throw','find','taskId','maxParallel','../../../utilities/create-no-new-messages-timeout','env','message','next','This\x20can\x20also\x20be\x20a\x20false\x20positive\x20caused\x20by\x20agents\x20that\x20did\x20not\x20shut\x20down\x20correctly.','status','readFileSync','existsSync','getTime','exit','SIGINT','VERBOSE_LOGGING','./distributed-agent.api','readdirSync','/nx.json','unlinkSync','join','Agent\x20','includes','../../../utilities/nx-imports','inherit','retryDuring','toString','../../../utilities/metric-logger','__esModule','configuration','startAgent','completed'];(function(_0x5597ce,_0x38e0d3){const _0x1e3d40=function(_0x2fdd01){while(--_0x2fdd01){_0x5597ce['push'](_0x5597ce['shift']());}};_0x1e3d40(++_0x38e0d3);}(a5_0x38e0,0x1cb));const a5_0x1e3d=function(_0x5597ce,_0x38e0d3){_0x5597ce=_0x5597ce-0x0;let _0x1e3d40=a5_0x38e0[_0x5597ce];return _0x1e3d40;};'use strict';var __awaiter=this&&this[a5_0x1e3d('0x39')]||function(_0x377527,_0x57a2ee,_0xc2868b,_0x4138e6){function _0x1bd7e1(_0x1c7b06){return _0x1c7b06 instanceof _0xc2868b?_0x1c7b06:new _0xc2868b(function(_0x35b87d){_0x35b87d(_0x1c7b06);});}return new(_0xc2868b||(_0xc2868b=Promise))(function(_0x40a2e0,_0x2eae9b){function _0x57dfb4(_0x5a606a){try{_0x565fcc(_0x4138e6[a5_0x1e3d('0x56')](_0x5a606a));}catch(_0x143099){_0x2eae9b(_0x143099);}}function _0x4232cd(_0x971e2c){try{_0x565fcc(_0x4138e6[a5_0x1e3d('0x4f')](_0x971e2c));}catch(_0x396b31){_0x2eae9b(_0x396b31);}}function _0x565fcc(_0x96a0de){_0x96a0de[a5_0x1e3d('0x3e')]?_0x40a2e0(_0x96a0de['value']):_0x1bd7e1(_0x96a0de[a5_0x1e3d('0x1f')])[a5_0x1e3d('0x1b')](_0x57dfb4,_0x4232cd);}_0x565fcc((_0x4138e6=_0x4138e6[a5_0x1e3d('0x27')](_0x377527,_0x57a2ee||[]))['next']());});};Object['defineProperty'](exports,a5_0x1e3d('0xc'),{'value':!![]});exports[a5_0x1e3d('0xe')]=void 0x0;const child_process_1=require(a5_0x1e3d('0x40'));const fs_1=require('fs');const stripJsonComments=require(a5_0x1e3d('0x47'));const create_no_new_messages_timeout_1=require(a5_0x1e3d('0x53'));const environment_1=require('../../../utilities/environment');const metric_logger_1=require(a5_0x1e3d('0xb'));const waiter_1=require('../../../utilities/waiter');const print_run_group_error_1=require(a5_0x1e3d('0x15'));const distributed_agent_api_1=require(a5_0x1e3d('0x0'));const {output,workspaceRoot}=require(a5_0x1e3d('0x7'));function executeTasks(_0x47dda3,_0x4665bd){return __awaiter(this,void 0x0,void 0x0,function*(){let _0xcf7d0d=0x0;let _0x141e34=null;const _0x5ad54c=(0x0,create_no_new_messages_timeout_1[a5_0x1e3d('0x38')])();const _0x1205bd=new waiter_1[(a5_0x1e3d('0x48'))]();let _0x4a2456=[];const _0x343cb4=new Date();let _0x470b63=![];while(!![]){if(environment_1[a5_0x1e3d('0x5e')]){output[a5_0x1e3d('0x4c')]({'title':'Fetching\x20tasks...'});}_0x141e34=yield _0x4665bd[a5_0x1e3d('0x41')](_0x141e34?_0x141e34['executionId']:null,_0xcf7d0d,_0x4a2456);if(environment_1[a5_0x1e3d('0x5e')]){output[a5_0x1e3d('0x4c')]({'title':a5_0x1e3d('0x12'),'bodyLines':[a5_0x1e3d('0x21')+_0x141e34[a5_0x1e3d('0xf')],'retryDuring:\x20'+_0x141e34[a5_0x1e3d('0x9')],a5_0x1e3d('0x34')+_0x141e34[a5_0x1e3d('0x26')],'number\x20of\x20tasks:\x20'+_0x141e34[a5_0x1e3d('0x41')]['length'],a5_0x1e3d('0x2d')+_0x141e34[a5_0x1e3d('0x36')],a5_0x1e3d('0x31')+_0x141e34['maxParallel']]});}if(_0x141e34[a5_0x1e3d('0x36')]){output[a5_0x1e3d('0x43')]({'title':a5_0x1e3d('0x42'),'bodyLines':['Error:',_0x141e34[a5_0x1e3d('0x36')]]});process[a5_0x1e3d('0x5c')](0x0);}if((_0x141e34===null||_0x141e34===void 0x0?void 0x0:_0x141e34[a5_0x1e3d('0x9')])&&(_0x141e34===null||_0x141e34===void 0x0?void 0x0:_0x141e34[a5_0x1e3d('0x9')])!==0x0&&!_0x470b63&&new Date()[a5_0x1e3d('0x5b')]()-_0x343cb4[a5_0x1e3d('0x5b')]()>_0x141e34[a5_0x1e3d('0x9')]){yield _0x1205bd[a5_0x1e3d('0x1c')]();continue;}if(_0x141e34[a5_0x1e3d('0xf')])return;_0x5ad54c(_0x141e34[a5_0x1e3d('0x41')]['map'](_0x149bd8=>_0x149bd8[a5_0x1e3d('0x51')])[a5_0x1e3d('0x4')](''));if(!_0x141e34[a5_0x1e3d('0x26')]){if(environment_1[a5_0x1e3d('0x5e')]){output[a5_0x1e3d('0x4c')]({'title':a5_0x1e3d('0x3a')});}yield _0x1205bd['wait']();_0xcf7d0d=0x0;_0x4a2456=[];continue;}_0x1205bd['reset']();_0x470b63=!![];const _0x5ba249=invokeTasksUsingRunMany(_0x47dda3,_0x141e34[a5_0x1e3d('0x26')],_0x141e34[a5_0x1e3d('0x41')],_0x141e34[a5_0x1e3d('0x52')]);_0xcf7d0d=_0x5ba249['completedStatusCode'];_0x4a2456=_0x5ba249[a5_0x1e3d('0x29')];}});}function readCompletedTasks(_0x3fc5c5,_0xef9aad){const _0x180740=a5_0x1e3d('0x13')+_0xef9aad+').\x20Tasks\x20hashes\x20haven\x27t\x20been\x20recorded.';let _0x330639;try{const _0x3dd758=_0x3fc5c5[a5_0x1e3d('0x28')]||a5_0x1e3d('0x2c');const _0x3eb121=_0x3dd758+a5_0x1e3d('0x30')+_0xef9aad;_0x330639=JSON[a5_0x1e3d('0x1a')]((0x0,fs_1[a5_0x1e3d('0x59')])(_0x3eb121)[a5_0x1e3d('0xa')]());(0x0,fs_1[a5_0x1e3d('0x3')])(_0x3eb121);}catch(_0x4715c3){throw new Error(_0x180740);}if(_0x330639[a5_0x1e3d('0x1e')]==0x0){throw new Error(_0x180740);}return _0x330639;}function invokeTasksUsingRunMany(_0x8e90c0,_0x2de27c,_0x588381,_0x37164b){let _0x35ca7e=0x0;const _0x4c5a62=[];for(const _0x1715eb of groupByTarget(_0x588381)){const _0x5afac1=_0x1715eb[a5_0x1e3d('0xd')]?a5_0x1e3d('0x2e')+_0x1715eb[a5_0x1e3d('0xd')]:'';const _0x1d16c0=_0x37164b>0x1?a5_0x1e3d('0x20')+_0x37164b:'';const _0x351f6a=a5_0x1e3d('0x10')+_0x1715eb[a5_0x1e3d('0x37')]+'\x20'+_0x5afac1+a5_0x1e3d('0x14')+_0x1715eb[a5_0x1e3d('0x22')][a5_0x1e3d('0x4')](',')+'\x20'+_0x1715eb[a5_0x1e3d('0x35')]+_0x1d16c0;if(environment_1[a5_0x1e3d('0x5e')]){output['note']({'title':a5_0x1e3d('0x46')+_0x351f6a+'\x27'});}try{(0x0,child_process_1['execSync'])(_0x351f6a,{'stdio':['inherit','inherit',a5_0x1e3d('0x8')],'env':Object[a5_0x1e3d('0x3c')](Object[a5_0x1e3d('0x3c')]({},process[a5_0x1e3d('0x54')]),{'NX_CACHE_FAILURES':a5_0x1e3d('0x17'),'NX_CLOUD_DISTRIBUTED_EXECUTION_ID':_0x2de27c})});_0x4c5a62[a5_0x1e3d('0x49')](...readCompletedTasks(_0x8e90c0,_0x2de27c));}catch(_0x215355){if(_0x215355[a5_0x1e3d('0x58')]===environment_1[a5_0x1e3d('0x16')]){throw _0x215355;}else{_0x35ca7e=0x1;_0x4c5a62[a5_0x1e3d('0x49')](...readCompletedTasks(_0x8e90c0,_0x2de27c));}}}return{'completedStatusCode':_0x35ca7e,'completedTasks':_0x4c5a62};}function groupByTarget(_0x161f25){const _0x234404=[];_0x161f25['forEach'](_0x5d2338=>{const _0x20516c=_0x234404[a5_0x1e3d('0x50')](_0x5c7c32=>_0x5c7c32[a5_0x1e3d('0x37')]===_0x5d2338['target']&&_0x5c7c32[a5_0x1e3d('0xd')]===_0x5d2338[a5_0x1e3d('0xd')]);if(_0x20516c){_0x20516c['projects'][a5_0x1e3d('0x49')](_0x5d2338['projectName']);}else{_0x234404[a5_0x1e3d('0x49')]({'target':_0x5d2338['target'],'projects':[_0x5d2338[a5_0x1e3d('0x2f')]],'params':_0x5d2338['params'],'configuration':_0x5d2338['configuration']});}});return _0x234404;}function getAgentName(){if(process[a5_0x1e3d('0x54')][a5_0x1e3d('0x3b')]!==undefined){return process[a5_0x1e3d('0x54')][a5_0x1e3d('0x3b')];}else if(process[a5_0x1e3d('0x54')][a5_0x1e3d('0x45')]!==undefined&&process['env'][a5_0x1e3d('0x23')]){return process[a5_0x1e3d('0x54')][a5_0x1e3d('0x23')];}else if(process[a5_0x1e3d('0x54')]['CIRCLECI']!==undefined&&process[a5_0x1e3d('0x54')][a5_0x1e3d('0x24')]){return process[a5_0x1e3d('0x54')]['CIRCLE_JOB'];}else{return a5_0x1e3d('0x5')+Math[a5_0x1e3d('0x44')](Math[a5_0x1e3d('0x4e')]()*0x186a0);}}function createAgentLockfileAndSetUpListeners(_0x3ad806,_0x3d47f8,_0xb9d94e){const _0x1c4fb2=_0x3d47f8[a5_0x1e3d('0x28')]||'./node_modules/.cache/nx';const _0x225a52=_0x1c4fb2+'/lockfiles';const _0x440a03=_0x225a52+'/'+_0xb9d94e+a5_0x1e3d('0x32');if(!(0x0,fs_1[a5_0x1e3d('0x5a')])(_0x225a52)){(0x0,fs_1['mkdirSync'])(_0x225a52,{'recursive':!![]});}const _0x5f634f=(0x0,fs_1[a5_0x1e3d('0x1')])(_0x225a52);if(_0x5f634f[a5_0x1e3d('0x1e')]){if(_0x5f634f[a5_0x1e3d('0x6')](_0xb9d94e+a5_0x1e3d('0x32'))){output[a5_0x1e3d('0x43')]({'title':'Duplicate\x20Agent\x20ID\x20Detected','bodyLines':[a5_0x1e3d('0x18'),'',a5_0x1e3d('0x1d')]});process['exit'](0x1);}output[a5_0x1e3d('0x3f')]({'title':a5_0x1e3d('0x4d'),'bodyLines':[a5_0x1e3d('0x4b'),'',a5_0x1e3d('0x57'),'If\x20you\x20believe\x20this\x20is\x20the\x20case,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22.']});}(0x0,fs_1['writeFileSync'])(_0x440a03,'');process['on'](a5_0x1e3d('0x5c'),_0x321826=>{cleanupAgentLockfile(_0x440a03,_0x321826);});process['on'](a5_0x1e3d('0x2b'),()=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x3ad806[a5_0x1e3d('0x3d')](a5_0x1e3d('0x4a'));cleanupAgentLockfile(_0x440a03,0x1);}));process['on'](a5_0x1e3d('0x5d'),()=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x3ad806[a5_0x1e3d('0x3d')]('Agent\x20was\x20terminated\x20via\x20SIGINT');cleanupAgentLockfile(_0x440a03,0x1);}));}function cleanupAgentLockfile(_0x5f0cd0,_0x2cca68){if((0x0,fs_1['existsSync'])(_0x5f0cd0)){(0x0,fs_1['unlinkSync'])(_0x5f0cd0);process[a5_0x1e3d('0x5c')](_0x2cca68);}}function startAgent(){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x42f41d=(0x0,environment_1[a5_0x1e3d('0x19')])();if(!_0x42f41d){(0x0,print_run_group_error_1['printRunGroupError'])();return process['exit'](0x1);}output[a5_0x1e3d('0x4c')]({'title':a5_0x1e3d('0x25')});const _0x4f7038=JSON[a5_0x1e3d('0x1a')](stripJsonComments((0x0,fs_1[a5_0x1e3d('0x59')])(workspaceRoot+a5_0x1e3d('0x2'))[a5_0x1e3d('0xa')]()))['tasksRunnerOptions'][a5_0x1e3d('0x11')]['options'];const _0x344676=getAgentName();const _0x35abd1=new distributed_agent_api_1['DistributedAgentApi'](_0x4f7038,_0x42f41d,_0x344676);createAgentLockfileAndSetUpListeners(_0x35abd1,_0x4f7038,_0x344676);return executeTasks(_0x4f7038,_0x35abd1)[a5_0x1e3d('0x1b')](_0x4f654b=>__awaiter(this,void 0x0,void 0x0,function*(){yield(0x0,metric_logger_1['submitRunMetrics'])(_0x4f7038);return _0x4f654b;}))[a5_0x1e3d('0x2a')](_0x16e94f=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x35abd1['completeRunGroupWithError'](a5_0x1e3d('0x33')+_0x16e94f[a5_0x1e3d('0x55')]+'\x22');throw _0x16e94f;}));});}exports['startAgent']=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 child_process_1 = require("child_process");
14
+ const fs_1 = require("fs");
15
+ const stripJsonComments = require("strip-json-comments");
16
+ const create_unchanged_value_timeout_1 = require("../../../utilities/create-unchanged-value-timeout");
17
+ const environment_1 = require("../../../utilities/environment");
18
+ const metric_logger_1 = require("../../../utilities/metric-logger");
19
+ const waiter_1 = require("../../../utilities/waiter");
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 { output, workspaceRoot } = require('../../../utilities/nx-imports');
23
+ function executeTasks(options, api) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ let completedStatusCode = 0;
26
+ let apiResponse = null;
27
+ const failIfSameTasksAfterTimeout = (0, create_unchanged_value_timeout_1.createUnchangedValueTimeout)({
28
+ title: `No new messages received after ${environment_1.NO_MESSAGES_TIMEOUT / 1000} seconds`,
29
+ timeout: environment_1.NO_MESSAGES_TIMEOUT,
30
+ });
31
+ const waiter = new waiter_1.Waiter();
32
+ let completedTasks = [];
33
+ const startTime = new Date();
34
+ let executedAnyTasks = false;
35
+ while (true) {
36
+ if (environment_1.VERBOSE_LOGGING) {
37
+ output.note({
38
+ title: 'Fetching tasks...',
39
+ });
40
+ }
41
+ apiResponse = yield api.tasks(apiResponse ? apiResponse.executionId : null, completedStatusCode, completedTasks);
42
+ if (environment_1.VERBOSE_LOGGING) {
43
+ output.note({
44
+ title: 'API Response',
45
+ bodyLines: [
46
+ `completed: ${apiResponse.completed}`,
47
+ `status: ${apiResponse.status}`,
48
+ `retryDuring: ${apiResponse.retryDuring}`,
49
+ `executionId: ${apiResponse.executionId}`,
50
+ `number of tasks: ${apiResponse.tasks.length}`,
51
+ `error: ${apiResponse.criticalErrorMessage}`,
52
+ `maxParallel: ${apiResponse.maxParallel}`,
53
+ ],
54
+ });
55
+ }
56
+ if (apiResponse.criticalErrorMessage) {
57
+ output.error({
58
+ title: 'Distributed Execution Terminated',
59
+ bodyLines: ['Error:', apiResponse.criticalErrorMessage],
60
+ });
61
+ process.exit(0);
62
+ }
63
+ // run group is completed but it might be a rerun
64
+ // we will try several times before going further and
65
+ // completed the response
66
+ // we only do it if we haven't executed any tasks
67
+ if ((apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.retryDuring) &&
68
+ (apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.retryDuring) !== 0 &&
69
+ !executedAnyTasks &&
70
+ new Date().getTime() - startTime.getTime() > apiResponse.retryDuring) {
71
+ yield waiter.wait();
72
+ continue;
73
+ }
74
+ if ((apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.status) !== undefined) {
75
+ if (apiResponse.status === 'RUN_GROUP_COMPLETED' ||
76
+ apiResponse.status === 'NO_FURTHER_TASKS_TO_RUN') {
77
+ return;
78
+ }
79
+ }
80
+ else if (apiResponse.completed) {
81
+ return;
82
+ }
83
+ // if status is present that use the status instead of completed, otherwise use completed
84
+ failIfSameTasksAfterTimeout(apiResponse.tasks.map((t) => t.taskId).join(''));
85
+ if (!apiResponse.executionId) {
86
+ if (environment_1.VERBOSE_LOGGING) {
87
+ output.note({
88
+ title: 'Waiting...',
89
+ });
90
+ }
91
+ yield waiter.wait();
92
+ completedStatusCode = 0;
93
+ completedTasks = [];
94
+ continue;
95
+ }
96
+ waiter.reset();
97
+ executedAnyTasks = true;
98
+ const r = invokeTasksUsingRunMany(options, apiResponse.executionId, apiResponse.tasks, apiResponse.maxParallel);
99
+ completedStatusCode = r.completedStatusCode;
100
+ completedTasks = r.completedTasks;
101
+ }
102
+ });
103
+ }
104
+ function readCompletedTasks(options, distributedExecutionId) {
105
+ const errorMessage = `Command execution failed (distributed task execution: ${distributedExecutionId}). Tasks hashes haven\'t been recorded.`;
106
+ let completedTasks;
107
+ try {
108
+ const cacheDirectory = options.cacheDirectory || './node_modules/.cache/nx';
109
+ const taskHashesFile = `${cacheDirectory}/tasks-hashes-${distributedExecutionId}`;
110
+ completedTasks = JSON.parse((0, fs_1.readFileSync)(taskHashesFile).toString());
111
+ // remove it such that if the next command crashes we don't read an obsolete file
112
+ (0, fs_1.unlinkSync)(taskHashesFile);
113
+ }
114
+ catch (e) {
115
+ throw new Error(errorMessage);
116
+ }
117
+ if (completedTasks.length == 0) {
118
+ throw new Error(errorMessage);
119
+ }
120
+ return completedTasks;
121
+ }
122
+ function invokeTasksUsingRunMany(options, executionId, tasks, maxParallel) {
123
+ let completedStatusCode = 0;
124
+ const completedTasks = [];
125
+ for (const g of groupByTarget(tasks)) {
126
+ const config = g.configuration ? `--configuration=${g.configuration}` : ``;
127
+ const parallel = maxParallel > 1 ? ` --parallel --max-parallel=${maxParallel}` : ``;
128
+ // TODO use pnpx or yarn when needed
129
+ const command = `npx nx run-many --target=${g.target} ${config} --projects=${g.projects.join(',')} ${g.params}${parallel}`;
130
+ if (environment_1.VERBOSE_LOGGING) {
131
+ output.note({
132
+ title: `Executing: '${command}'`,
133
+ });
134
+ }
135
+ try {
136
+ (0, child_process_1.execSync)(command, {
137
+ stdio: ['inherit', 'inherit', 'inherit'],
138
+ env: Object.assign(Object.assign({}, process.env), { NX_CACHE_FAILURES: 'true', NX_CLOUD_DISTRIBUTED_EXECUTION_ID: executionId }),
139
+ });
140
+ completedTasks.push(...readCompletedTasks(options, executionId));
141
+ }
142
+ catch (e) {
143
+ if (e.status === environment_1.DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE) {
144
+ throw e;
145
+ }
146
+ else {
147
+ completedStatusCode = 1;
148
+ completedTasks.push(...readCompletedTasks(options, executionId));
149
+ }
150
+ }
151
+ }
152
+ return { completedStatusCode, completedTasks };
153
+ }
154
+ function groupByTarget(tasks) {
155
+ const res = [];
156
+ tasks.forEach((t) => {
157
+ const r = res.find((rr) => rr.target === t.target && rr.configuration === t.configuration);
158
+ if (r) {
159
+ r.projects.push(t.projectName);
160
+ }
161
+ else {
162
+ res.push({
163
+ target: t.target,
164
+ projects: [t.projectName],
165
+ params: t.params,
166
+ configuration: t.configuration,
167
+ });
168
+ }
169
+ });
170
+ return res;
171
+ }
172
+ function getAgentName() {
173
+ if (process.env.NX_AGENT_NAME !== undefined) {
174
+ return process.env.NX_AGENT_NAME;
175
+ }
176
+ else if (process.env.CIRCLECI !== undefined && process.env.CIRCLE_STAGE) {
177
+ return process.env.CIRCLE_STAGE;
178
+ }
179
+ else if (process.env.CIRCLECI !== undefined && process.env.CIRCLE_JOB) {
180
+ return process.env.CIRCLE_JOB;
181
+ }
182
+ else {
183
+ return `Agent ${Math.floor(Math.random() * 100000)}`;
184
+ }
185
+ }
186
+ function createAgentLockfileAndSetUpListeners(api, options, agentName) {
187
+ const cacheDirectory = options.cacheDirectory || './node_modules/.cache/nx';
188
+ const lockFileDirectory = `${cacheDirectory}/lockfiles`;
189
+ const lockFilePath = `${lockFileDirectory}/${agentName}.lock`;
190
+ if (!(0, fs_1.existsSync)(lockFileDirectory)) {
191
+ (0, fs_1.mkdirSync)(lockFileDirectory, { recursive: true });
192
+ }
193
+ // Check for other agents' lockfiles and warn if exist
194
+ const lockFiles = (0, fs_1.readdirSync)(lockFileDirectory);
195
+ if (lockFiles.length) {
196
+ // Check to make sure the current agent name is not in use (only 1/100000 ^ 2 chance of this)
197
+ if (lockFiles.includes(`${agentName}.lock`)) {
198
+ output.error({
199
+ title: 'Duplicate Agent ID Detected',
200
+ bodyLines: [
201
+ 'We have detected another agent with this ID running in this workspace. This should not happen.',
202
+ '',
203
+ 'End all currently running agents, run "npx nx-cloud clean-up-agents", and try again.',
204
+ ],
205
+ });
206
+ process.exit(1);
207
+ }
208
+ output.warn({
209
+ title: 'Other Nx Cloud Agents Detected',
210
+ bodyLines: [
211
+ 'We have detected other agents running in this workspace. This can cause unexpected behavior.',
212
+ '',
213
+ 'This can also be a false positive caused by agents that did not shut down correctly.',
214
+ 'If you believe this is the case, run "npx nx-cloud clean-up-agents".',
215
+ ],
216
+ });
217
+ }
218
+ (0, fs_1.writeFileSync)(lockFilePath, '');
219
+ process.on('exit', (code) => {
220
+ cleanupAgentLockfile(lockFilePath, code);
221
+ });
222
+ process.on('SIGTERM', () => __awaiter(this, void 0, void 0, function* () {
223
+ yield api.completeRunGroupWithError('Agent was terminated via SIGTERM');
224
+ cleanupAgentLockfile(lockFilePath, 1);
225
+ }));
226
+ process.on('SIGINT', () => __awaiter(this, void 0, void 0, function* () {
227
+ yield api.completeRunGroupWithError('Agent was terminated via SIGINT');
228
+ cleanupAgentLockfile(lockFilePath, 1);
229
+ }));
230
+ }
231
+ function cleanupAgentLockfile(lockFilePath, code) {
232
+ if ((0, fs_1.existsSync)(lockFilePath)) {
233
+ (0, fs_1.unlinkSync)(lockFilePath);
234
+ process.exit(code);
235
+ }
236
+ }
237
+ function startAgent() {
238
+ return __awaiter(this, void 0, void 0, function* () {
239
+ const runGroup = (0, environment_1.getRunGroup)();
240
+ if (!runGroup) {
241
+ (0, print_run_group_error_1.printRunGroupError)();
242
+ return process.exit(1);
243
+ }
244
+ output.note({
245
+ title: 'Starting an agent for running Nx tasks',
246
+ });
247
+ const options = JSON.parse(stripJsonComments((0, fs_1.readFileSync)(`${workspaceRoot}/nx.json`).toString())).tasksRunnerOptions.default.options;
248
+ const agentName = getAgentName();
249
+ const api = new distributed_agent_api_1.DistributedAgentApi(options, runGroup, agentName);
250
+ createAgentLockfileAndSetUpListeners(api, options, agentName);
251
+ return executeTasks(options, api)
252
+ .then((res) => __awaiter(this, void 0, void 0, function* () {
253
+ yield (0, metric_logger_1.submitRunMetrics)(options);
254
+ return res;
255
+ }))
256
+ .catch((e) => __awaiter(this, void 0, void 0, function* () {
257
+ yield api.completeRunGroupWithError(`Critical Error in Agent: "${e.message}"`);
258
+ throw e;
259
+ }));
260
+ });
261
+ }
262
+ exports.startAgent = startAgent;
263
+ //# sourceMappingURL=distributed-agent.impl.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"distributed-agent.impl.js","sourceRoot":"","sources":["../../../../../../../../libs/nx-packages/nx-cloud/lib/core/runners/distributed-agent/distributed-agent.impl.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAAyC;AACzC,2BAOY;AACZ,yDAAyD;AACzD,sGAA+F;AAC/F,gEAIwC;AACxC,oEAAoE;AACpE,sDAAmD;AACnD,6EAAuE;AAOvE,mEAA8D;AAE9D,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,+BAA+B,CAAC,CAAC;AAE3E,SAAe,YAAY,CACzB,OAA+B,EAC/B,GAAwB;;QAExB,IAAI,mBAAmB,GAAG,CAAC,CAAC;QAC5B,IAAI,WAAW,GAA4B,IAAI,CAAC;QAChD,MAAM,2BAA2B,GAAG,IAAA,2DAA0B,GAAE,CAAC;QACjE,MAAM,MAAM,GAAG,IAAI,eAAM,EAAE,CAAC;QAE5B,IAAI,cAAc,GAAG,EAAwC,CAAC;QAE9D,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;QAC7B,IAAI,gBAAgB,GAAG,KAAK,CAAC;QAE7B,OAAO,IAAI,EAAE;YACX,IAAI,6BAAe,EAAE;gBACnB,MAAM,CAAC,IAAI,CAAC;oBACV,KAAK,EAAE,mBAAmB;iBAC3B,CAAC,CAAC;aACJ;YAED,WAAY,GAAG,MAAM,GAAG,CAAC,KAAK,CAC5B,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC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C,CAAC;QAElE,oCAAoC,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;QAE9D,OAAO,YAAY,CAAC,OAAO,EAAE,GAAG,CAAC;aAC9B,IAAI,CAAC,CAAO,GAAG,EAAE,EAAE;YAClB,MAAM,IAAA,gCAAgB,EAAC,OAAO,CAAC,CAAC;YAChC,OAAO,GAAG,CAAC;QACb,CAAC,CAAA,CAAC;aACD,KAAK,CAAC,CAAO,CAAC,EAAE,EAAE;YACjB,MAAM,GAAG,CAAC,yBAAyB,CACjC,6BAA6B,CAAC,CAAC,OAAO,GAAG,CAC1C,CAAC;YACF,MAAM,CAAC,CAAC;QACV,CAAC,CAAA,CAAC,CAAC;IACP,CAAC;CAAA;AA/BD,gCA+BC"}
1
+ {"version":3,"file":"distributed-agent.impl.js","sourceRoot":"","sources":["../../../../../../../../libs/nx-packages/nx-cloud/lib/core/runners/distributed-agent/distributed-agent.impl.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAAyC;AACzC,2BAOY;AACZ,yDAAyD;AACzD,sGAAgG;AAChG,gEAKwC;AACxC,oEAAoE;AACpE,sDAAmD;AACnD,6EAAuE;AAOvE,mEAA8D;AAE9D,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,+BAA+B,CAAC,CAAC;AAE3E,SAAe,YAAY,CACzB,OAA+B,EAC/B,GAAwB;;QAExB,IAAI,mBAAmB,GAAG,CAAC,CAAC;QAC5B,IAAI,WAAW,GAA4B,IAAI,CAAC;QAChD,MAAM,2BAA2B,GAAG,IAAA,4DAA2B,EAAC;YAC9D,KAAK,EAAE,kCACL,iCAAmB,GAAG,IACxB,UAAU;YACV,OAAO,EAAE,iCAAmB;SAC7B,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,eAAM,EAAE,CAAC;QAE5B,IAAI,cAAc,GAAG,EAAwC,CAAC;QAE9D,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;QAC7B,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,yBAAW,GAAE,CAAC;QAC/B,IAAI,CAAC,QAAQ,EAAE;YACb,IAAA,0CAAkB,GAAE,CAAC;YACrB,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACxB;QAED,MAAM,CAAC,IAAI,CAAC;YACV,KAAK,EAAE,wCAAwC;SAChD,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CACxB,iBAAiB,CAAC,IAAA,iBAAY,EAAC,GAAG,aAAa,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,CACvE,CAAC,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC;QAErC,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;QACjC,MAAM,GAAG,GAAG,IAAI,2CAAmB,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;QAElE,oCAAoC,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;QAE9D,OAAO,YAAY,CAAC,OAAO,EAAE,GAAG,CAAC;aAC9B,IAAI,CAAC,CAAO,GAAG,EAAE,EAAE;YAClB,MAAM,IAAA,gCAAgB,EAAC,OAAO,CAAC,CAAC;YAChC,OAAO,GAAG,CAAC;QACb,CAAC,CAAA,CAAC;aACD,KAAK,CAAC,CAAO,CAAC,EAAE,EAAE;YACjB,MAAM,GAAG,CAAC,yBAAyB,CACjC,6BAA6B,CAAC,CAAC,OAAO,GAAG,CAC1C,CAAC;YACF,MAAM,CAAC,CAAC;QACV,CAAC,CAAA,CAAC,CAAC;IACP,CAAC;CAAA;AA/BD,gCA+BC"}
@@ -1 +1,143 @@
1
- const a6_0x2eae=['start','__esModule','NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT','throw','response','project','defineProperty','runGroup:\x20','recordMetric','note','apiAxiosInstance','__awaiter','true','dteStatus','completeRunGroup','stopAgentsOnFailure','serializeOverrides','/nx-cloud/executions/complete-run-group','next','RUNNER_FAILURE_PERF_ENTRY','dteStart','configuration','../../../utilities/environment','createStartRequest','false','Completing\x20run\x20group\x20with\x20an\x20error','/nx-cloud/executions/status','../../../utilities/axios','VERBOSE_LOGGING','data','target','message','value','mapRespToPerfEntry','post','apply','parallel','agentCount','getBranch','error:\x20','hash','exit','NX_CLOUD_DISTRIBUTED_EXECUTION_STOP_AGENTS_ON_FAILURE','map','createApiAxiosInstance','createMetricRecorder','completeRunGroupWithError','error','Workspace\x20is\x20disabled.\x20Cannot\x20perform\x20distributed\x20task\x20executions.','axiosException','then','axiosMultipleTries','maxParallel','../../../utilities/serializer-overrides'];(function(_0x148e81,_0x2eaeaa){const _0x59679f=function(_0x41bc10){while(--_0x41bc10){_0x148e81['push'](_0x148e81['shift']());}};_0x59679f(++_0x2eaeaa);}(a6_0x2eae,0xba));const a6_0x5967=function(_0x148e81,_0x2eaeaa){_0x148e81=_0x148e81-0x0;let _0x59679f=a6_0x2eae[_0x148e81];return _0x59679f;};'use strict';var __awaiter=this&&this[a6_0x5967('0x29')]||function(_0x251848,_0x2f7ee3,_0x2b42c8,_0x55677f){function _0x3802f6(_0x46a2dc){return _0x46a2dc instanceof _0x2b42c8?_0x46a2dc:new _0x2b42c8(function(_0x138b89){_0x138b89(_0x46a2dc);});}return new(_0x2b42c8||(_0x2b42c8=Promise))(function(_0x5cb4ef,_0x2cbf0b){function _0x4e73a5(_0x2f74e6){try{_0x5189c4(_0x55677f[a6_0x5967('0x30')](_0x2f74e6));}catch(_0x4af4a8){_0x2cbf0b(_0x4af4a8);}}function _0x330582(_0xd28144){try{_0x5189c4(_0x55677f[a6_0x5967('0x21')](_0xd28144));}catch(_0x4f9a86){_0x2cbf0b(_0x4f9a86);}}function _0x5189c4(_0x1d90ba){_0x1d90ba['done']?_0x5cb4ef(_0x1d90ba['value']):_0x3802f6(_0x1d90ba[a6_0x5967('0x8')])[a6_0x5967('0x1a')](_0x4e73a5,_0x330582);}_0x5189c4((_0x55677f=_0x55677f[a6_0x5967('0xb')](_0x251848,_0x2f7ee3||[]))[a6_0x5967('0x30')]());});};Object[a6_0x5967('0x24')](exports,a6_0x5967('0x1f'),{'value':!![]});exports['createStartRequest']=exports['DistributedExecutionApi']=void 0x0;const axios_1=require(a6_0x5967('0x3'));const environment_1=require(a6_0x5967('0x34'));const metric_logger_1=require('../../../utilities/metric-logger');const serializer_overrides_1=require(a6_0x5967('0x1d'));const {output}=require('../../../utilities/nx-imports');class DistributedExecutionApi{constructor(_0x1e4428){this['apiAxiosInstance']=(0x0,axios_1[a6_0x5967('0x14')])(_0x1e4428);}[a6_0x5967('0x1e')](_0x330930){var _0x2b9e75;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x515cd8=(0x0,metric_logger_1[a6_0x5967('0x15')])(a6_0x5967('0x32'));let _0x31debf;if(environment_1[a6_0x5967('0x4')]){output[a6_0x5967('0x27')]({'title':'Starting\x20a\x20distributed\x20execution','bodyLines':[JSON['stringify'](_0x330930,null,0x2)]});}try{_0x31debf=yield(0x0,axios_1[a6_0x5967('0x1b')])(()=>this[a6_0x5967('0x28')][a6_0x5967('0xa')]('/nx-cloud/executions/start',_0x330930));_0x515cd8[a6_0x5967('0x26')]((0x0,metric_logger_1['mapRespToPerfEntry'])(_0x31debf));}catch(_0x8b8e8){_0x515cd8[a6_0x5967('0x26')](((_0x2b9e75=_0x8b8e8===null||_0x8b8e8===void 0x0?void 0x0:_0x8b8e8[a6_0x5967('0x19')])===null||_0x2b9e75===void 0x0?void 0x0:_0x2b9e75['response'])?(0x0,metric_logger_1[a6_0x5967('0x9')])(_0x8b8e8[a6_0x5967('0x19')][a6_0x5967('0x22')]):metric_logger_1[a6_0x5967('0x31')]);throw _0x8b8e8;}if(!_0x31debf[a6_0x5967('0x5')]['enabled']){throw new Error(a6_0x5967('0x18'));}if(_0x31debf[a6_0x5967('0x5')][a6_0x5967('0x17')]){throw new Error(_0x31debf[a6_0x5967('0x5')][a6_0x5967('0x17')]);}return _0x31debf[a6_0x5967('0x5')]['id'];});}['status'](_0x1077d4){var _0x3abddd;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x29df50=(0x0,metric_logger_1[a6_0x5967('0x15')])(a6_0x5967('0x2b'));try{const _0x46011f=yield(0x0,axios_1[a6_0x5967('0x1b')])(()=>this['apiAxiosInstance'][a6_0x5967('0xa')](a6_0x5967('0x2'),{'id':_0x1077d4}));_0x29df50[a6_0x5967('0x26')]((0x0,metric_logger_1[a6_0x5967('0x9')])(_0x46011f));return _0x46011f[a6_0x5967('0x5')];}catch(_0x140512){_0x29df50[a6_0x5967('0x26')](((_0x3abddd=_0x140512===null||_0x140512===void 0x0?void 0x0:_0x140512['axiosException'])===null||_0x3abddd===void 0x0?void 0x0:_0x3abddd[a6_0x5967('0x22')])?(0x0,metric_logger_1[a6_0x5967('0x9')])(_0x140512[a6_0x5967('0x19')][a6_0x5967('0x22')]):metric_logger_1[a6_0x5967('0x31')]);output['error']({'title':_0x140512[a6_0x5967('0x7')]});process[a6_0x5967('0x11')](0x1);}});}[a6_0x5967('0x16')](_0x1e2572,_0x1af70e){var _0x92f4d8;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x113088=(0x0,metric_logger_1[a6_0x5967('0x15')])(a6_0x5967('0x2c'));if(environment_1[a6_0x5967('0x4')]){output[a6_0x5967('0x27')]({'title':a6_0x5967('0x1'),'bodyLines':[a6_0x5967('0x25')+_0x1e2572,a6_0x5967('0xf')+_0x1af70e]});}try{const _0x4e8bc8=yield(0x0,axios_1['axiosMultipleTries'])(()=>this[a6_0x5967('0x28')]['post'](a6_0x5967('0x2f'),{'runGroup':_0x1e2572,'criticalErrorMessage':_0x1af70e}),0x3);_0x113088[a6_0x5967('0x26')]((0x0,metric_logger_1[a6_0x5967('0x9')])(_0x4e8bc8));}catch(_0x4ae4cf){_0x113088[a6_0x5967('0x26')](((_0x92f4d8=_0x4ae4cf===null||_0x4ae4cf===void 0x0?void 0x0:_0x4ae4cf[a6_0x5967('0x19')])===null||_0x92f4d8===void 0x0?void 0x0:_0x92f4d8[a6_0x5967('0x22')])?(0x0,metric_logger_1[a6_0x5967('0x9')])(_0x4ae4cf['axiosException'][a6_0x5967('0x22')]):metric_logger_1[a6_0x5967('0x31')]);}});}}exports['DistributedExecutionApi']=DistributedExecutionApi;function createStartRequest(_0x12cdd5,_0x38a75a,_0x3dfd7a){const _0x42f338=_0x38a75a['map'](_0x2a714c=>{return _0x2a714c[a6_0x5967('0x13')](_0x4b3853=>{return{'taskId':_0x4b3853['id'],'hash':_0x4b3853[a6_0x5967('0x10')],'projectName':_0x4b3853[a6_0x5967('0x6')][a6_0x5967('0x23')],'target':_0x4b3853[a6_0x5967('0x6')][a6_0x5967('0x6')],'configuration':_0x4b3853[a6_0x5967('0x6')][a6_0x5967('0x33')]||null,'params':(0x0,serializer_overrides_1[a6_0x5967('0x2e')])(_0x4b3853)};});});const _0x4679a0={'command':(0x0,environment_1['parseCommand'])(),'branch':(0x0,environment_1[a6_0x5967('0xe')])(),'runGroup':_0x12cdd5,'tasks':_0x42f338,'maxParallel':calculateMaxParallel(_0x3dfd7a)};if(environment_1[a6_0x5967('0x20')]){_0x4679a0[a6_0x5967('0xd')]=environment_1[a6_0x5967('0x20')];}if(!environment_1[a6_0x5967('0x12')]){_0x4679a0[a6_0x5967('0x2d')]=![];}return _0x4679a0;}exports[a6_0x5967('0x35')]=createStartRequest;function calculateMaxParallel(_0x47f755){if(_0x47f755[a6_0x5967('0xc')]===a6_0x5967('0x0')||_0x47f755['parallel']===![]){return 0x1;}else if(_0x47f755[a6_0x5967('0xc')]===a6_0x5967('0x2a')||_0x47f755[a6_0x5967('0xc')]===!![]){return Number(_0x47f755[a6_0x5967('0x1c')]||0x3);}else if(_0x47f755[a6_0x5967('0xc')]===undefined){return _0x47f755[a6_0x5967('0x1c')]?Number(_0x47f755[a6_0x5967('0x1c')]):0x3;}else{return Number(_0x47f755[a6_0x5967('0xc')])||0x3;}}
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.createStartRequest = exports.DistributedExecutionApi = 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 serializer_overrides_1 = require("../../../utilities/serializer-overrides");
17
+ const { output } = require('../../../utilities/nx-imports');
18
+ class DistributedExecutionApi {
19
+ constructor(options) {
20
+ this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options);
21
+ }
22
+ start(params) {
23
+ var _a;
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const recorder = (0, metric_logger_1.createMetricRecorder)('dteStart');
26
+ let resp;
27
+ if (environment_1.VERBOSE_LOGGING) {
28
+ output.note({
29
+ title: 'Starting a distributed execution',
30
+ bodyLines: [JSON.stringify(params, null, 2)],
31
+ });
32
+ }
33
+ try {
34
+ resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/start', params));
35
+ recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
36
+ }
37
+ catch (e) {
38
+ recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
39
+ ? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
40
+ : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
41
+ throw e;
42
+ }
43
+ if (!resp.data.enabled) {
44
+ throw new Error(`Workspace is disabled. Cannot perform distributed task executions.`);
45
+ }
46
+ if (resp.data.error) {
47
+ throw new Error(resp.data.error);
48
+ }
49
+ return resp.data.id;
50
+ });
51
+ }
52
+ status(id) {
53
+ var _a;
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const recorder = (0, metric_logger_1.createMetricRecorder)('dteStatus');
56
+ try {
57
+ const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/status', {
58
+ id,
59
+ }));
60
+ recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
61
+ return resp.data;
62
+ }
63
+ catch (e) {
64
+ recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
65
+ ? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
66
+ : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
67
+ output.error({
68
+ title: e.message,
69
+ });
70
+ process.exit(1);
71
+ }
72
+ });
73
+ }
74
+ completeRunGroupWithError(runGroup, error) {
75
+ var _a;
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ const recorder = (0, metric_logger_1.createMetricRecorder)('completeRunGroup');
78
+ if (environment_1.VERBOSE_LOGGING) {
79
+ output.note({
80
+ title: 'Completing run group with an error',
81
+ bodyLines: [`runGroup: ${runGroup}`, `error: ${error}`],
82
+ });
83
+ }
84
+ try {
85
+ const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/complete-run-group', {
86
+ runGroup: runGroup,
87
+ criticalErrorMessage: error,
88
+ }), 3);
89
+ recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
90
+ }
91
+ catch (e) {
92
+ recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
93
+ ? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
94
+ : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
95
+ }
96
+ });
97
+ }
98
+ }
99
+ exports.DistributedExecutionApi = DistributedExecutionApi;
100
+ function createStartRequest(runGroup, task, options) {
101
+ const tasksToExecute = task.map((arr) => {
102
+ return arr.map((t) => {
103
+ return {
104
+ taskId: t.id,
105
+ hash: t.hash,
106
+ projectName: t.target.project,
107
+ target: t.target.target,
108
+ configuration: t.target.configuration || null,
109
+ params: (0, serializer_overrides_1.serializeOverrides)(t),
110
+ };
111
+ });
112
+ });
113
+ const request = {
114
+ command: (0, environment_1.parseCommand)(),
115
+ branch: (0, environment_1.getBranch)(),
116
+ runGroup,
117
+ tasks: tasksToExecute,
118
+ maxParallel: calculateMaxParallel(options),
119
+ };
120
+ if (environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT) {
121
+ request.agentCount = environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT;
122
+ }
123
+ if (!environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_STOP_AGENTS_ON_FAILURE) {
124
+ request.stopAgentsOnFailure = false;
125
+ }
126
+ return request;
127
+ }
128
+ exports.createStartRequest = createStartRequest;
129
+ function calculateMaxParallel(options) {
130
+ if (options.parallel === 'false' || options.parallel === false) {
131
+ return 1;
132
+ }
133
+ else if (options.parallel === 'true' || options.parallel === true) {
134
+ return Number(options.maxParallel || 3);
135
+ }
136
+ else if (options.parallel === undefined) {
137
+ return options.maxParallel ? Number(options.maxParallel) : 3;
138
+ }
139
+ else {
140
+ return Number(options.parallel) || 3;
141
+ }
142
+ }
143
+ //# sourceMappingURL=distributed-execution.api.js.map