@nrwl/nx-cloud 15.0.3 → 15.0.4-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core/api/error-reporter.api.js +36 -1
- package/lib/core/api/run-group.api.js +68 -1
- package/lib/core/runners/cloud-enabled/cloud-enabled-life-cycle.d.ts +1 -3
- package/lib/core/runners/cloud-enabled/cloud-enabled-life-cycle.js +84 -1
- package/lib/core/runners/cloud-enabled/cloud-enabled-life-cycle.js.map +1 -1
- package/lib/core/runners/cloud-enabled/cloud-enabled.runner.js +288 -1
- package/lib/core/runners/cloud-enabled/cloud-enabled.runner.js.map +1 -1
- package/lib/core/runners/cloud-enabled/cloud-remote-cache.js +113 -1
- package/lib/core/runners/cloud-enabled/cloud-run.api.js +167 -1
- package/lib/core/runners/cloud-enabled/id-generator.js +16 -1
- package/lib/core/runners/distributed-agent/distributed-agent.api.js +79 -1
- package/lib/core/runners/distributed-agent/distributed-agent.impl.js +269 -1
- package/lib/core/runners/distributed-execution/distributed-execution.api.js +143 -1
- package/lib/core/runners/distributed-execution/distributed-execution.runner.js +241 -1
- package/lib/core/runners/distributed-execution/distributed-execution.runner.js.map +1 -1
- package/lib/core/runners/distributed-execution/split-task-graph-into-stages.js +37 -1
- package/lib/core/runners/distributed-execution/task-graph-creator.js +77 -1
- package/package.json +1 -1
|
@@ -1 +1,269 @@
|
|
|
1
|
-
const a6_0x1fcd=['options','getNxCacheDirectory','exit','We\x20have\x20detected\x20other\x20agents\x20running\x20in\x20this\x20workspace.\x20This\x20can\x20cause\x20unexpected\x20behavior.','retryDuring','NX_AGENT_NAME','../../../utilities/nx-imports','status:\x20','Duplicate\x20Agent\x20ID\x20Detected','submitRunMetrics','find','npx\x20nx\x20run-many\x20--target=','inherit','Waiter','DistributedAgentApi','next','defineProperty','getRunGroup','criticalErrorMessage','done','completed:\x20','then','readFileSync','__awaiter','error:\x20','completeRunGroupWithError','apply','RUN_GROUP_COMPLETED','warn','/nx.json','Waiting...','mkdirSync','printInvalidRunnerError','parse','No\x20new\x20messages\x20received\x20after\x20','number\x20of\x20tasks:\x20','Executing:\x20\x27','Distributed\x20Execution\x20Terminated','reset','retryDuring:\x20','existsSync','message','tasks','executionId:\x20','This\x20can\x20also\x20be\x20a\x20false\x20positive\x20caused\x20by\x20agents\x20that\x20did\x20not\x20shut\x20down\x20correctly.','configuration','printRunGroupError','taskId','throw','@nrwl/nx-cloud','Starting\x20an\x20agent\x20for\x20running\x20Nx\x20tasks','error','join','projects','__esModule','CIRCLE_STAGE','wait','CIRCLECI','status','We\x20have\x20detected\x20another\x20agent\x20with\x20this\x20ID\x20running\x20in\x20this\x20workspace.\x20This\x20should\x20not\x20happen.','map','/lockfiles','note','strip-json-comments','startAgent','tasksRunnerOptions','NO_MESSAGES_TIMEOUT','VERBOSE_LOGGING','DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE','SIGTERM','toString','completedTasks','SIGINT','Critical\x20Error\x20in\x20Agent:\x20\x22','readdirSync','If\x20you\x20believe\x20this\x20is\x20the\x20case,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22.','maxParallel','CIRCLE_JOB','.lock','env','projectName','value','--configuration=','params','Agent\x20','../../../utilities/environment','completedStatusCode','Other\x20Nx\x20Cloud\x20Agents\x20Detected','push','runner','true','executionId','getTime','assign','API\x20Response','length','completed','createUnchangedValueTimeout','ignore','target','./distributed-agent.api','Agent\x20was\x20terminated\x20via\x20SIGTERM','\x20seconds','writeFileSync','Error:','unlinkSync','\x20--projects=','Command\x20execution\x20failed\x20(distributed\x20task\x20execution:\x20','random','\x20--parallel\x20--max-parallel='];(function(_0xc65dbe,_0x1fcda0){const _0x54d58d=function(_0x457f6d){while(--_0x457f6d){_0xc65dbe['push'](_0xc65dbe['shift']());}};_0x54d58d(++_0x1fcda0);}(a6_0x1fcd,0x98));const a6_0x54d5=function(_0xc65dbe,_0x1fcda0){_0xc65dbe=_0xc65dbe-0x0;let _0x54d58d=a6_0x1fcd[_0xc65dbe];return _0x54d58d;};'use strict';var __awaiter=this&&this[a6_0x54d5('0x5b')]||function(_0x538c06,_0x33f151,_0x3af8c9,_0xef80a0){function _0x459845(_0x328c29){return _0x328c29 instanceof _0x3af8c9?_0x328c29:new _0x3af8c9(function(_0x2601b1){_0x2601b1(_0x328c29);});}return new(_0x3af8c9||(_0x3af8c9=Promise))(function(_0xd84f19,_0x2d6533){function _0x317be5(_0x1d55d8){try{_0x94b7c4(_0xef80a0['next'](_0x1d55d8));}catch(_0x31331c){_0x2d6533(_0x31331c);}}function _0x58f57a(_0xcf4bb){try{_0x94b7c4(_0xef80a0[a6_0x54d5('0x6')](_0xcf4bb));}catch(_0x4381d9){_0x2d6533(_0x4381d9);}}function _0x94b7c4(_0x1f4394){_0x1f4394[a6_0x54d5('0x57')]?_0xd84f19(_0x1f4394['value']):_0x459845(_0x1f4394[a6_0x54d5('0x27')])[a6_0x54d5('0x59')](_0x317be5,_0x58f57a);}_0x94b7c4((_0xef80a0=_0xef80a0[a6_0x54d5('0x5e')](_0x538c06,_0x33f151||[]))[a6_0x54d5('0x53')]());});};Object[a6_0x54d5('0x54')](exports,a6_0x54d5('0xc'),{'value':!![]});exports[a6_0x54d5('0x16')]=void 0x0;const child_process_1=require('child_process');const fs_1=require('fs');const stripJsonComments=require(a6_0x54d5('0x15'));const create_unchanged_value_timeout_1=require('../../../utilities/create-unchanged-value-timeout');const environment_1=require(a6_0x54d5('0x2b'));const metric_logger_1=require('../../../utilities/metric-logger');const waiter_1=require('../../../utilities/waiter');const print_run_group_error_1=require('../../error/print-run-group-error');const distributed_agent_api_1=require(a6_0x54d5('0x3a'));const print_invalid_runner_error_1=require('../../error/print-invalid-runner-error');const {output,workspaceRoot}=require(a6_0x54d5('0x4a'));function executeTasks(_0x4790f2,_0x5186e0){return __awaiter(this,void 0x0,void 0x0,function*(){let _0x11f859=0x0;let _0x5038e3=null;const _0x4204f2=(0x0,create_unchanged_value_timeout_1[a6_0x54d5('0x37')])({'title':a6_0x54d5('0x66')+environment_1[a6_0x54d5('0x18')]/0x3e8+a6_0x54d5('0x3c'),'timeout':environment_1[a6_0x54d5('0x18')]});const _0x4542e1=new waiter_1[(a6_0x54d5('0x51'))]();let _0x2bda6b=[];const _0x1b4c53=new Date();let _0x12c428=![];while(!![]){if(environment_1[a6_0x54d5('0x19')]){output['note']({'title':'Fetching\x20tasks...'});}_0x5038e3=yield _0x5186e0[a6_0x54d5('0x0')](_0x5038e3?_0x5038e3[a6_0x54d5('0x31')]:null,_0x11f859,_0x2bda6b);if(environment_1[a6_0x54d5('0x19')]){output[a6_0x54d5('0x14')]({'title':a6_0x54d5('0x34'),'bodyLines':[a6_0x54d5('0x58')+_0x5038e3['completed'],a6_0x54d5('0x4b')+_0x5038e3[a6_0x54d5('0x10')],a6_0x54d5('0x6b')+_0x5038e3[a6_0x54d5('0x48')],a6_0x54d5('0x1')+_0x5038e3[a6_0x54d5('0x31')],a6_0x54d5('0x67')+_0x5038e3[a6_0x54d5('0x0')][a6_0x54d5('0x35')],a6_0x54d5('0x5c')+_0x5038e3[a6_0x54d5('0x56')],'maxParallel:\x20'+_0x5038e3[a6_0x54d5('0x22')]]});}if(_0x5038e3[a6_0x54d5('0x56')]){output['error']({'title':a6_0x54d5('0x69'),'bodyLines':[a6_0x54d5('0x3e'),_0x5038e3[a6_0x54d5('0x56')]]});process[a6_0x54d5('0x46')](0x0);}if((_0x5038e3===null||_0x5038e3===void 0x0?void 0x0:_0x5038e3['retryDuring'])&&(_0x5038e3===null||_0x5038e3===void 0x0?void 0x0:_0x5038e3['retryDuring'])!==0x0&&!_0x12c428&&new Date()[a6_0x54d5('0x32')]()-_0x1b4c53[a6_0x54d5('0x32')]()>_0x5038e3[a6_0x54d5('0x48')]){yield _0x4542e1[a6_0x54d5('0xe')]();continue;}if((_0x5038e3===null||_0x5038e3===void 0x0?void 0x0:_0x5038e3['status'])!==undefined){if(_0x5038e3['status']===a6_0x54d5('0x5f')||_0x5038e3[a6_0x54d5('0x10')]==='NO_FURTHER_TASKS_TO_RUN'){return;}}else if(_0x5038e3[a6_0x54d5('0x36')]){return;}_0x4204f2(_0x5038e3['tasks'][a6_0x54d5('0x12')](_0x31df43=>_0x31df43[a6_0x54d5('0x5')])[a6_0x54d5('0xa')](''));if(!_0x5038e3[a6_0x54d5('0x31')]){if(environment_1[a6_0x54d5('0x19')]){output[a6_0x54d5('0x14')]({'title':a6_0x54d5('0x62')});}yield _0x4542e1[a6_0x54d5('0xe')]();_0x11f859=0x0;_0x2bda6b=[];continue;}_0x4542e1[a6_0x54d5('0x6a')]();_0x12c428=!![];const _0x237d41=invokeTasksUsingRunMany(_0x4790f2,_0x5038e3[a6_0x54d5('0x31')],_0x5038e3[a6_0x54d5('0x0')],_0x5038e3[a6_0x54d5('0x22')]);_0x11f859=_0x237d41[a6_0x54d5('0x2c')];_0x2bda6b=_0x237d41[a6_0x54d5('0x1d')];}});}function readCompletedTasks(_0x5bda1a,_0x359c6d){const _0x3939c8=a6_0x54d5('0x41')+_0x359c6d+').\x20Tasks\x20hashes\x20haven\x27t\x20been\x20recorded.';let _0x1f1349;try{const _0x3b35a5=(0x0,environment_1[a6_0x54d5('0x45')])(_0x5bda1a);const _0x3d1d8a=_0x3b35a5+'/tasks-hashes-'+_0x359c6d;_0x1f1349=JSON['parse']((0x0,fs_1[a6_0x54d5('0x5a')])(_0x3d1d8a)[a6_0x54d5('0x1c')]());(0x0,fs_1[a6_0x54d5('0x3f')])(_0x3d1d8a);}catch(_0xd99c7c){throw new Error(_0x3939c8);}if(_0x1f1349[a6_0x54d5('0x35')]==0x0){throw new Error(_0x3939c8);}return _0x1f1349;}function invokeTasksUsingRunMany(_0x473683,_0x213518,_0x58ec82,_0x6eea39){let _0x65b739=0x0;const _0x3345f5=[];for(const _0xd9d4fe of groupByTarget(_0x58ec82)){const _0x1f9e89=_0xd9d4fe[a6_0x54d5('0x3')]?a6_0x54d5('0x28')+_0xd9d4fe[a6_0x54d5('0x3')]:'';const _0x40c2b7=_0x6eea39>0x1?a6_0x54d5('0x43')+_0x6eea39:'';const _0x4a9a10=a6_0x54d5('0x4f')+_0xd9d4fe['target']+'\x20'+_0x1f9e89+a6_0x54d5('0x40')+_0xd9d4fe['projects']['join'](',')+'\x20'+_0xd9d4fe[a6_0x54d5('0x29')]+_0x40c2b7;if(environment_1['VERBOSE_LOGGING']){output[a6_0x54d5('0x14')]({'title':a6_0x54d5('0x68')+_0x4a9a10+'\x27'});}try{(0x0,child_process_1['execSync'])(_0x4a9a10,{'stdio':[a6_0x54d5('0x38'),a6_0x54d5('0x50'),'inherit'],'env':Object[a6_0x54d5('0x33')](Object[a6_0x54d5('0x33')]({},process['env']),{'NX_CACHE_FAILURES':a6_0x54d5('0x30'),'NX_CLOUD_DISTRIBUTED_EXECUTION_ID':_0x213518,'NX_STREAM_OUTPUT':'true','NX_PREFIX_OUTPUT':'true'})});_0x3345f5[a6_0x54d5('0x2e')](...readCompletedTasks(_0x473683,_0x213518));}catch(_0x5f083b){if(_0x5f083b[a6_0x54d5('0x10')]===environment_1[a6_0x54d5('0x1a')]){throw _0x5f083b;}else{_0x65b739=0x1;_0x3345f5['push'](...readCompletedTasks(_0x473683,_0x213518));}}}return{'completedStatusCode':_0x65b739,'completedTasks':_0x3345f5};}function groupByTarget(_0x4ee6d4){const _0x19a23a=[];_0x4ee6d4['forEach'](_0xa4c1ea=>{const _0x477a29=_0x19a23a[a6_0x54d5('0x4e')](_0x160c17=>_0x160c17[a6_0x54d5('0x39')]===_0xa4c1ea[a6_0x54d5('0x39')]&&_0x160c17[a6_0x54d5('0x3')]===_0xa4c1ea[a6_0x54d5('0x3')]);if(_0x477a29){_0x477a29[a6_0x54d5('0xb')]['push'](_0xa4c1ea[a6_0x54d5('0x26')]);}else{_0x19a23a[a6_0x54d5('0x2e')]({'target':_0xa4c1ea[a6_0x54d5('0x39')],'projects':[_0xa4c1ea[a6_0x54d5('0x26')]],'params':_0xa4c1ea[a6_0x54d5('0x29')],'configuration':_0xa4c1ea[a6_0x54d5('0x3')]});}});return _0x19a23a;}function getAgentName(){if(process[a6_0x54d5('0x25')][a6_0x54d5('0x49')]!==undefined){return process['env'][a6_0x54d5('0x49')];}else if(process[a6_0x54d5('0x25')]['CIRCLECI']!==undefined&&process[a6_0x54d5('0x25')][a6_0x54d5('0xd')]){return process['env'][a6_0x54d5('0xd')];}else if(process[a6_0x54d5('0x25')][a6_0x54d5('0xf')]!==undefined&&process[a6_0x54d5('0x25')][a6_0x54d5('0x23')]){return process[a6_0x54d5('0x25')][a6_0x54d5('0x23')];}else{return a6_0x54d5('0x2a')+Math['floor'](Math[a6_0x54d5('0x42')]()*0x186a0);}}function createAgentLockfileAndSetUpListeners(_0x106efa,_0x8ef844,_0x1db8e4){const _0xcbdb41=(0x0,environment_1['getNxCacheDirectory'])(_0x8ef844);const _0x5965b4=_0xcbdb41+a6_0x54d5('0x13');const _0x1e58c5=_0x5965b4+'/'+_0x1db8e4+a6_0x54d5('0x24');if(!(0x0,fs_1[a6_0x54d5('0x6c')])(_0x5965b4)){(0x0,fs_1[a6_0x54d5('0x63')])(_0x5965b4,{'recursive':!![]});}const _0x2567fc=(0x0,fs_1[a6_0x54d5('0x20')])(_0x5965b4);if(_0x2567fc[a6_0x54d5('0x35')]){if(_0x2567fc['includes'](_0x1db8e4+a6_0x54d5('0x24'))){output[a6_0x54d5('0x9')]({'title':a6_0x54d5('0x4c'),'bodyLines':[a6_0x54d5('0x11'),'','End\x20all\x20currently\x20running\x20agents,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22,\x20and\x20try\x20again.']});process[a6_0x54d5('0x46')](0x1);}output[a6_0x54d5('0x60')]({'title':a6_0x54d5('0x2d'),'bodyLines':[a6_0x54d5('0x47'),'',a6_0x54d5('0x2'),a6_0x54d5('0x21')]});}(0x0,fs_1[a6_0x54d5('0x3d')])(_0x1e58c5,'');process['on'](a6_0x54d5('0x46'),_0x370970=>{cleanupAgentLockfile(_0x1e58c5,_0x370970);});process['on'](a6_0x54d5('0x1b'),()=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x106efa[a6_0x54d5('0x5d')](a6_0x54d5('0x3b'));cleanupAgentLockfile(_0x1e58c5,0x1);}));process['on'](a6_0x54d5('0x1e'),()=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x106efa[a6_0x54d5('0x5d')]('Agent\x20was\x20terminated\x20via\x20SIGINT');cleanupAgentLockfile(_0x1e58c5,0x1);}));}function cleanupAgentLockfile(_0x118995,_0x302789){if((0x0,fs_1[a6_0x54d5('0x6c')])(_0x118995)){(0x0,fs_1[a6_0x54d5('0x3f')])(_0x118995);process[a6_0x54d5('0x46')](_0x302789);}}function startAgent(){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x21e9cd=(0x0,environment_1[a6_0x54d5('0x55')])();if(!_0x21e9cd){(0x0,print_run_group_error_1[a6_0x54d5('0x4')])();return process[a6_0x54d5('0x46')](0x1);}output[a6_0x54d5('0x14')]({'title':a6_0x54d5('0x8')});const _0x3a89a7=JSON[a6_0x54d5('0x65')](stripJsonComments((0x0,fs_1[a6_0x54d5('0x5a')])(workspaceRoot+a6_0x54d5('0x61'))[a6_0x54d5('0x1c')]()))[a6_0x54d5('0x17')]['default'];if(_0x3a89a7[a6_0x54d5('0x2f')]!==a6_0x54d5('0x7')){(0x0,print_invalid_runner_error_1[a6_0x54d5('0x64')])();return process[a6_0x54d5('0x46')](0x1);}const _0x2b577c=_0x3a89a7[a6_0x54d5('0x44')];const _0x10584a=getAgentName();const _0x16a0db=new distributed_agent_api_1[(a6_0x54d5('0x52'))](_0x2b577c,_0x21e9cd,_0x10584a);createAgentLockfileAndSetUpListeners(_0x16a0db,_0x2b577c,_0x10584a);return executeTasks(_0x2b577c,_0x16a0db)[a6_0x54d5('0x59')](_0x169f89=>__awaiter(this,void 0x0,void 0x0,function*(){yield(0x0,metric_logger_1[a6_0x54d5('0x4d')])(_0x2b577c);return _0x169f89;}))['catch'](_0x3682d1=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x16a0db['completeRunGroupWithError'](a6_0x54d5('0x1f')+_0x3682d1[a6_0x54d5('0x6d')]+'\x22');throw _0x3682d1;}));});}exports[a6_0x54d5('0x16')]=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 print_invalid_runner_error_1 = require("../../error/print-invalid-runner-error");
|
|
23
|
+
const { output, workspaceRoot } = require('../../../utilities/nx-imports');
|
|
24
|
+
function executeTasks(options, api) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
let completedStatusCode = 0;
|
|
27
|
+
let apiResponse = null;
|
|
28
|
+
const failIfSameTasksAfterTimeout = (0, create_unchanged_value_timeout_1.createUnchangedValueTimeout)({
|
|
29
|
+
title: `No new messages received after ${environment_1.NO_MESSAGES_TIMEOUT / 1000} seconds`,
|
|
30
|
+
timeout: environment_1.NO_MESSAGES_TIMEOUT,
|
|
31
|
+
});
|
|
32
|
+
const waiter = new waiter_1.Waiter();
|
|
33
|
+
let completedTasks = [];
|
|
34
|
+
const startTime = new Date();
|
|
35
|
+
let executedAnyTasks = false;
|
|
36
|
+
while (true) {
|
|
37
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
38
|
+
output.note({
|
|
39
|
+
title: 'Fetching tasks...',
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
apiResponse = yield api.tasks(apiResponse ? apiResponse.executionId : null, completedStatusCode, completedTasks);
|
|
43
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
44
|
+
output.note({
|
|
45
|
+
title: 'API Response',
|
|
46
|
+
bodyLines: [
|
|
47
|
+
`completed: ${apiResponse.completed}`,
|
|
48
|
+
`status: ${apiResponse.status}`,
|
|
49
|
+
`retryDuring: ${apiResponse.retryDuring}`,
|
|
50
|
+
`executionId: ${apiResponse.executionId}`,
|
|
51
|
+
`number of tasks: ${apiResponse.tasks.length}`,
|
|
52
|
+
`error: ${apiResponse.criticalErrorMessage}`,
|
|
53
|
+
`maxParallel: ${apiResponse.maxParallel}`,
|
|
54
|
+
],
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (apiResponse.criticalErrorMessage) {
|
|
58
|
+
output.error({
|
|
59
|
+
title: 'Distributed Execution Terminated',
|
|
60
|
+
bodyLines: ['Error:', apiResponse.criticalErrorMessage],
|
|
61
|
+
});
|
|
62
|
+
process.exit(0);
|
|
63
|
+
}
|
|
64
|
+
// run group is completed but it might be a rerun
|
|
65
|
+
// we will try several times before going further and
|
|
66
|
+
// completed the response
|
|
67
|
+
// we only do it if we haven't executed any tasks
|
|
68
|
+
if ((apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.retryDuring) &&
|
|
69
|
+
(apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.retryDuring) !== 0 &&
|
|
70
|
+
!executedAnyTasks &&
|
|
71
|
+
new Date().getTime() - startTime.getTime() > apiResponse.retryDuring) {
|
|
72
|
+
yield waiter.wait();
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if ((apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.status) !== undefined) {
|
|
76
|
+
if (apiResponse.status === 'RUN_GROUP_COMPLETED' ||
|
|
77
|
+
apiResponse.status === 'NO_FURTHER_TASKS_TO_RUN') {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if (apiResponse.completed) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// if status is present that use the status instead of completed, otherwise use completed
|
|
85
|
+
failIfSameTasksAfterTimeout(apiResponse.tasks.map((t) => t.taskId).join(''));
|
|
86
|
+
if (!apiResponse.executionId) {
|
|
87
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
88
|
+
output.note({
|
|
89
|
+
title: 'Waiting...',
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
yield waiter.wait();
|
|
93
|
+
completedStatusCode = 0;
|
|
94
|
+
completedTasks = [];
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
waiter.reset();
|
|
98
|
+
executedAnyTasks = true;
|
|
99
|
+
const r = invokeTasksUsingRunMany(options, apiResponse.executionId, apiResponse.tasks, apiResponse.maxParallel);
|
|
100
|
+
completedStatusCode = r.completedStatusCode;
|
|
101
|
+
completedTasks = r.completedTasks;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function readCompletedTasks(options, distributedExecutionId) {
|
|
106
|
+
const errorMessage = `Command execution failed (distributed task execution: ${distributedExecutionId}). Tasks hashes haven\'t been recorded.`;
|
|
107
|
+
let completedTasks;
|
|
108
|
+
try {
|
|
109
|
+
const cacheDirectory = (0, environment_1.getNxCacheDirectory)(options);
|
|
110
|
+
const taskHashesFile = `${cacheDirectory}/tasks-hashes-${distributedExecutionId}`;
|
|
111
|
+
completedTasks = JSON.parse((0, fs_1.readFileSync)(taskHashesFile).toString());
|
|
112
|
+
// remove it such that if the next command crashes we don't read an obsolete file
|
|
113
|
+
(0, fs_1.unlinkSync)(taskHashesFile);
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
throw new Error(errorMessage);
|
|
117
|
+
}
|
|
118
|
+
if (completedTasks.length == 0) {
|
|
119
|
+
throw new Error(errorMessage);
|
|
120
|
+
}
|
|
121
|
+
return completedTasks;
|
|
122
|
+
}
|
|
123
|
+
function invokeTasksUsingRunMany(options, executionId, tasks, maxParallel) {
|
|
124
|
+
let completedStatusCode = 0;
|
|
125
|
+
const completedTasks = [];
|
|
126
|
+
for (const g of groupByTarget(tasks)) {
|
|
127
|
+
const config = g.configuration ? `--configuration=${g.configuration}` : ``;
|
|
128
|
+
const parallel = maxParallel > 1 ? ` --parallel --max-parallel=${maxParallel}` : ``;
|
|
129
|
+
// TODO use pnpx or yarn when needed
|
|
130
|
+
const command = `npx nx run-many --target=${g.target} ${config} --projects=${g.projects.join(',')} ${g.params}${parallel}`;
|
|
131
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
132
|
+
output.note({
|
|
133
|
+
title: `Executing: '${command}'`,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
(0, child_process_1.execSync)(command, {
|
|
138
|
+
stdio: ['ignore', 'inherit', 'inherit'],
|
|
139
|
+
env: Object.assign(Object.assign({}, process.env), { NX_CACHE_FAILURES: 'true', NX_CLOUD_DISTRIBUTED_EXECUTION_ID: executionId, NX_STREAM_OUTPUT: 'true', NX_PREFIX_OUTPUT: 'true' }),
|
|
140
|
+
});
|
|
141
|
+
completedTasks.push(...readCompletedTasks(options, executionId));
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
if (e.status === environment_1.DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE) {
|
|
145
|
+
throw e;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
completedStatusCode = 1;
|
|
149
|
+
completedTasks.push(...readCompletedTasks(options, executionId));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return { completedStatusCode, completedTasks };
|
|
154
|
+
}
|
|
155
|
+
function groupByTarget(tasks) {
|
|
156
|
+
const res = [];
|
|
157
|
+
tasks.forEach((t) => {
|
|
158
|
+
const r = res.find((rr) => rr.target === t.target && rr.configuration === t.configuration);
|
|
159
|
+
if (r) {
|
|
160
|
+
r.projects.push(t.projectName);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
res.push({
|
|
164
|
+
target: t.target,
|
|
165
|
+
projects: [t.projectName],
|
|
166
|
+
params: t.params,
|
|
167
|
+
configuration: t.configuration,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
return res;
|
|
172
|
+
}
|
|
173
|
+
function getAgentName() {
|
|
174
|
+
if (process.env.NX_AGENT_NAME !== undefined) {
|
|
175
|
+
return process.env.NX_AGENT_NAME;
|
|
176
|
+
}
|
|
177
|
+
else if (process.env.CIRCLECI !== undefined && process.env.CIRCLE_STAGE) {
|
|
178
|
+
return process.env.CIRCLE_STAGE;
|
|
179
|
+
}
|
|
180
|
+
else if (process.env.CIRCLECI !== undefined && process.env.CIRCLE_JOB) {
|
|
181
|
+
return process.env.CIRCLE_JOB;
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
return `Agent ${Math.floor(Math.random() * 100000)}`;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function createAgentLockfileAndSetUpListeners(api, options, agentName) {
|
|
188
|
+
const cacheDirectory = (0, environment_1.getNxCacheDirectory)(options);
|
|
189
|
+
const lockFileDirectory = `${cacheDirectory}/lockfiles`;
|
|
190
|
+
const lockFilePath = `${lockFileDirectory}/${agentName}.lock`;
|
|
191
|
+
if (!(0, fs_1.existsSync)(lockFileDirectory)) {
|
|
192
|
+
(0, fs_1.mkdirSync)(lockFileDirectory, { recursive: true });
|
|
193
|
+
}
|
|
194
|
+
// Check for other agents' lockfiles and warn if exist
|
|
195
|
+
const lockFiles = (0, fs_1.readdirSync)(lockFileDirectory);
|
|
196
|
+
if (lockFiles.length) {
|
|
197
|
+
// Check to make sure the current agent name is not in use (only 1/100000 ^ 2 chance of this)
|
|
198
|
+
if (lockFiles.includes(`${agentName}.lock`)) {
|
|
199
|
+
output.error({
|
|
200
|
+
title: 'Duplicate Agent ID Detected',
|
|
201
|
+
bodyLines: [
|
|
202
|
+
'We have detected another agent with this ID running in this workspace. This should not happen.',
|
|
203
|
+
'',
|
|
204
|
+
'End all currently running agents, run "npx nx-cloud clean-up-agents", and try again.',
|
|
205
|
+
],
|
|
206
|
+
});
|
|
207
|
+
process.exit(1);
|
|
208
|
+
}
|
|
209
|
+
output.warn({
|
|
210
|
+
title: 'Other Nx Cloud Agents Detected',
|
|
211
|
+
bodyLines: [
|
|
212
|
+
'We have detected other agents running in this workspace. This can cause unexpected behavior.',
|
|
213
|
+
'',
|
|
214
|
+
'This can also be a false positive caused by agents that did not shut down correctly.',
|
|
215
|
+
'If you believe this is the case, run "npx nx-cloud clean-up-agents".',
|
|
216
|
+
],
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
(0, fs_1.writeFileSync)(lockFilePath, '');
|
|
220
|
+
process.on('exit', (code) => {
|
|
221
|
+
cleanupAgentLockfile(lockFilePath, code);
|
|
222
|
+
});
|
|
223
|
+
process.on('SIGTERM', () => __awaiter(this, void 0, void 0, function* () {
|
|
224
|
+
yield api.completeRunGroupWithError('Agent was terminated via SIGTERM');
|
|
225
|
+
cleanupAgentLockfile(lockFilePath, 1);
|
|
226
|
+
}));
|
|
227
|
+
process.on('SIGINT', () => __awaiter(this, void 0, void 0, function* () {
|
|
228
|
+
yield api.completeRunGroupWithError('Agent was terminated via SIGINT');
|
|
229
|
+
cleanupAgentLockfile(lockFilePath, 1);
|
|
230
|
+
}));
|
|
231
|
+
}
|
|
232
|
+
function cleanupAgentLockfile(lockFilePath, code) {
|
|
233
|
+
if ((0, fs_1.existsSync)(lockFilePath)) {
|
|
234
|
+
(0, fs_1.unlinkSync)(lockFilePath);
|
|
235
|
+
process.exit(code);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function startAgent() {
|
|
239
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
240
|
+
const runGroup = (0, environment_1.getRunGroup)();
|
|
241
|
+
if (!runGroup) {
|
|
242
|
+
(0, print_run_group_error_1.printRunGroupError)();
|
|
243
|
+
return process.exit(1);
|
|
244
|
+
}
|
|
245
|
+
output.note({
|
|
246
|
+
title: 'Starting an agent for running Nx tasks',
|
|
247
|
+
});
|
|
248
|
+
const defaultRunnerConfig = JSON.parse(stripJsonComments((0, fs_1.readFileSync)(`${workspaceRoot}/nx.json`).toString())).tasksRunnerOptions.default;
|
|
249
|
+
if (defaultRunnerConfig.runner !== '@nrwl/nx-cloud') {
|
|
250
|
+
(0, print_invalid_runner_error_1.printInvalidRunnerError)();
|
|
251
|
+
return process.exit(1);
|
|
252
|
+
}
|
|
253
|
+
const options = defaultRunnerConfig.options;
|
|
254
|
+
const agentName = getAgentName();
|
|
255
|
+
const api = new distributed_agent_api_1.DistributedAgentApi(options, runGroup, agentName);
|
|
256
|
+
createAgentLockfileAndSetUpListeners(api, options, agentName);
|
|
257
|
+
return executeTasks(options, api)
|
|
258
|
+
.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
259
|
+
yield (0, metric_logger_1.submitRunMetrics)(options);
|
|
260
|
+
return res;
|
|
261
|
+
}))
|
|
262
|
+
.catch((e) => __awaiter(this, void 0, void 0, function* () {
|
|
263
|
+
yield api.completeRunGroupWithError(`Critical Error in Agent: "${e.message}"`);
|
|
264
|
+
throw e;
|
|
265
|
+
}));
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
exports.startAgent = startAgent;
|
|
269
|
+
//# sourceMappingURL=distributed-agent.impl.js.map
|
|
@@ -1 +1,143 @@
|
|
|
1
|
-
|
|
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
|