Comparing version 14.0.3 to 14.0.4-beta.1
@@ -1,1 +0,65 @@ | ||
const a0_0x9aab=['apply','RunGroupApi','../../utilities/axios','defineProperty','message','recordMetric','exit','createMetricRecorder','post','RUNNER_FAILURE_PERF_ENTRY','axiosMultipleTries','next','apiAxiosInstance','createApiAxiosInstance','response','__esModule','value','error','/nx-cloud/executions/create-run-group','createRunGroup','axiosException','mapRespToPerfEntry','done','throw','completeRunGroup','/nx-cloud/executions/complete-run-group'];(function(_0x841bb8,_0x9aab37){const _0x4d79ae=function(_0x4c76ee){while(--_0x4c76ee){_0x841bb8['push'](_0x841bb8['shift']());}};_0x4d79ae(++_0x9aab37);}(a0_0x9aab,0x86));const a0_0x4d79=function(_0x841bb8,_0x9aab37){_0x841bb8=_0x841bb8-0x0;let _0x4d79ae=a0_0x9aab[_0x841bb8];return _0x4d79ae;};'use strict';var __awaiter=this&&this['__awaiter']||function(_0x2494d3,_0x83f74c,_0x1349d4,_0x386c69){function _0x2aa545(_0x6cb8b){return _0x6cb8b instanceof _0x1349d4?_0x6cb8b:new _0x1349d4(function(_0x5cd376){_0x5cd376(_0x6cb8b);});}return new(_0x1349d4||(_0x1349d4=Promise))(function(_0x25b436,_0x38ae08){function _0x308133(_0x2b0b7e){try{_0x476de1(_0x386c69[a0_0x4d79('0x7')](_0x2b0b7e));}catch(_0x1776a8){_0x38ae08(_0x1776a8);}}function _0x32708a(_0x36c0c9){try{_0x476de1(_0x386c69[a0_0x4d79('0x13')](_0x36c0c9));}catch(_0x48679f){_0x38ae08(_0x48679f);}}function _0x476de1(_0x5e5a76){_0x5e5a76[a0_0x4d79('0x12')]?_0x25b436(_0x5e5a76[a0_0x4d79('0xc')]):_0x2aa545(_0x5e5a76[a0_0x4d79('0xc')])['then'](_0x308133,_0x32708a);}_0x476de1((_0x386c69=_0x386c69[a0_0x4d79('0x16')](_0x2494d3,_0x83f74c||[]))[a0_0x4d79('0x7')]());});};Object[a0_0x4d79('0x19')](exports,a0_0x4d79('0xb'),{'value':!![]});exports[a0_0x4d79('0x17')]=void 0x0;const axios_1=require(a0_0x4d79('0x18'));const metric_logger_1=require('../../utilities/metric-logger');const {output}=require('../../utilities/nx-imports');class RunGroupApi{constructor(_0x298250){this[a0_0x4d79('0x8')]=(0x0,axios_1[a0_0x4d79('0x9')])(_0x298250);}[a0_0x4d79('0xf')](_0x20dd62,_0x2b9496){var _0xdbc02;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x132f86=(0x0,metric_logger_1[a0_0x4d79('0x3')])(a0_0x4d79('0xf'));try{const _0xe214dd=yield(0x0,axios_1[a0_0x4d79('0x6')])(()=>this[a0_0x4d79('0x8')]['post'](a0_0x4d79('0xe'),{'branch':_0x20dd62,'runGroup':_0x2b9496}));_0x132f86['recordMetric']((0x0,metric_logger_1[a0_0x4d79('0x11')])(_0xe214dd));}catch(_0x2c9ee8){_0x132f86[a0_0x4d79('0x1')](((_0xdbc02=_0x2c9ee8===null||_0x2c9ee8===void 0x0?void 0x0:_0x2c9ee8[a0_0x4d79('0x10')])===null||_0xdbc02===void 0x0?void 0x0:_0xdbc02[a0_0x4d79('0xa')])?(0x0,metric_logger_1[a0_0x4d79('0x11')])(_0x2c9ee8[a0_0x4d79('0x10')][a0_0x4d79('0xa')]):metric_logger_1[a0_0x4d79('0x5')]);output['error']({'title':_0x2c9ee8['message']});process[a0_0x4d79('0x2')](0x1);}});}[a0_0x4d79('0x14')](_0x4b80d2){var _0x42f671;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x1bb2a3=(0x0,metric_logger_1['createMetricRecorder'])(a0_0x4d79('0xf'));try{const _0x1ed5c4=yield(0x0,axios_1['axiosMultipleTries'])(()=>this[a0_0x4d79('0x8')][a0_0x4d79('0x4')](a0_0x4d79('0x15'),{'runGroup':_0x4b80d2}));_0x1bb2a3[a0_0x4d79('0x1')]((0x0,metric_logger_1['mapRespToPerfEntry'])(_0x1ed5c4));}catch(_0x5b19ae){_0x1bb2a3[a0_0x4d79('0x1')](((_0x42f671=_0x5b19ae===null||_0x5b19ae===void 0x0?void 0x0:_0x5b19ae[a0_0x4d79('0x10')])===null||_0x42f671===void 0x0?void 0x0:_0x42f671[a0_0x4d79('0xa')])?(0x0,metric_logger_1['mapRespToPerfEntry'])(_0x5b19ae[a0_0x4d79('0x10')]['response']):metric_logger_1[a0_0x4d79('0x5')]);output[a0_0x4d79('0xd')]({'title':_0x5b19ae[a0_0x4d79('0x0')]});process[a0_0x4d79('0x2')](0x1);}});}}exports['RunGroupApi']=RunGroupApi; | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RunGroupApi = void 0; | ||
const axios_1 = require("../../utilities/axios"); | ||
const metric_logger_1 = require("../../utilities/metric-logger"); | ||
const { output } = require('../../utilities/nx-imports'); | ||
class RunGroupApi { | ||
constructor(options) { | ||
this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options); | ||
} | ||
createRunGroup(branch, runGroup) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const recorder = (0, metric_logger_1.createMetricRecorder)('createRunGroup'); | ||
try { | ||
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/create-run-group', { | ||
branch: branch, | ||
runGroup: runGroup, | ||
})); | ||
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp)); | ||
} | ||
catch (e) { | ||
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response) | ||
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response) | ||
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY); | ||
output.error({ | ||
title: e.message, | ||
}); | ||
process.exit(1); | ||
} | ||
}); | ||
} | ||
completeRunGroup(runGroup) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const recorder = (0, metric_logger_1.createMetricRecorder)('createRunGroup'); | ||
try { | ||
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/complete-run-group', { | ||
runGroup: runGroup, | ||
})); | ||
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp)); | ||
} | ||
catch (e) { | ||
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response) | ||
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response) | ||
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY); | ||
output.error({ | ||
title: e.message, | ||
}); | ||
process.exit(1); | ||
} | ||
}); | ||
} | ||
} | ||
exports.RunGroupApi = RunGroupApi; | ||
//# sourceMappingURL=run-group.api.js.map |
@@ -9,2 +9,3 @@ import { E2EEncryption } from './e2e-encryption'; | ||
private downloadFile; | ||
private convertStreamIntoPromise; | ||
private createCommitFile; | ||
@@ -11,0 +12,0 @@ private createCommitFilePath; |
@@ -108,5 +108,3 @@ "use strict"; | ||
})); | ||
return new Promise((res) => { | ||
q.on('close', () => res(null)); | ||
}); | ||
return this.convertStreamIntoPromise(q); | ||
} | ||
@@ -117,8 +115,21 @@ else { | ||
})); | ||
return new Promise((res) => { | ||
q.on('close', () => res(null)); | ||
}); | ||
return this.convertStreamIntoPromise(q); | ||
} | ||
}); | ||
} | ||
convertStreamIntoPromise(q) { | ||
return new Promise((res, rej) => { | ||
q.on('error', (e) => { | ||
if (e.tarCode === 'TAR_ABORT' && | ||
e.message.indexOf('incorrect header check') > -1) { | ||
console.warn('FileStorage: Decompression OK, Trailing garbage ignored.'); | ||
res(null); | ||
} | ||
else { | ||
rej(e); | ||
} | ||
}); | ||
q.on('close', () => res(null)); | ||
}); | ||
} | ||
createCommitFile(commitFilePath) { | ||
@@ -125,0 +136,0 @@ (0, fs_1.writeFileSync)(commitFilePath, 'true'); |
@@ -1,1 +0,141 @@ | ||
const a0_0x55cc=['Cannot\x20find\x20task\x20','statuses','filter','path','overrides','outputObfuscator','length','nodes','taskId','join','CloudEnabledLifeCycle','configuration','local-cache-kept-existing','MAX_CHARACTERS_FAILED_TASK','hash','getTerminalOutput','target','TRUNCATED\x0a\x0a','runContext','startsWith','endTime','scheduledTasks','readTerminalOutputFile','status','MAX_CHARACTERS_CACHED_TASK','npm:','node_modules','code','../../../utilities/nx-imports','toISOString','terminalOutput','hashDetails','scheduleTask','tasks','startTask','toString','endTasks','cacheableOperations','slice','indexOf','__esModule','endCommand','obfuscate','skipNxCache','find','cache-miss','collectTerminalOutput','push','runtime','implicitDeps','local-cache-hit','project','terminalOutputs','local-cache','params','cacheStatus','cacheDirectory','updateStartedTask'];(function(_0x30411b,_0x55cc05){const _0x46a9c7=function(_0x4f99fb){while(--_0x4f99fb){_0x30411b['push'](_0x30411b['shift']());}};_0x46a9c7(++_0x55cc05);}(a0_0x55cc,0x12e));const a0_0x46a9=function(_0x30411b,_0x55cc05){_0x30411b=_0x30411b-0x0;let _0x46a9c7=a0_0x55cc[_0x30411b];return _0x46a9c7;};'use strict';Object['defineProperty'](exports,a0_0x46a9('0x1c'),{'value':!![]});exports[a0_0x46a9('0x38')]=void 0x0;const path=require('path');const path_1=require(a0_0x46a9('0x31'));const fs_1=require('fs');const environment_1=require('../../../utilities/environment');const {appRootPath,unparse}=require(a0_0x46a9('0x10'));class CloudEnabledLifeCycle{constructor(_0xde5dc1,_0x3f86e2,_0x588649,_0x3f73e0,_0x4f83d2,_0x2ed529,_0x26327e){this['runContext']=_0xde5dc1;this['cacheDirectory']=_0x3f86e2;this[a0_0x46a9('0x1f')]=_0x588649;this[a0_0x46a9('0x22')]=_0x3f73e0;this[a0_0x46a9('0x19')]=_0x4f83d2;this[a0_0x46a9('0x33')]=_0x2ed529;this[a0_0x46a9('0x15')]=_0x26327e;}[a0_0x46a9('0x14')](_0x404e20){this[a0_0x46a9('0x6')][a0_0x46a9('0x9')][a0_0x46a9('0x23')](_0x404e20);}[a0_0x46a9('0x16')](_0x4a519e){const _0x382aae=Object['assign']({},_0x4a519e[a0_0x46a9('0x32')]||{});if(_0x4a519e[a0_0x46a9('0x4')][a0_0x46a9('0x39')]){_0x382aae[a0_0x46a9('0x39')]=_0x4a519e[a0_0x46a9('0x4')][a0_0x46a9('0x39')];}this[a0_0x46a9('0x15')]['push']({'taskId':_0x4a519e['id'],'startTime':new Date()[a0_0x46a9('0x11')](),'target':_0x4a519e['target'][a0_0x46a9('0x4')],'projectName':_0x4a519e['target'][a0_0x46a9('0x27')],'hash':_0x4a519e[a0_0x46a9('0x2')],'hashDetails':this['cleanUpHashDetails'](_0x4a519e[a0_0x46a9('0x13')]),'params':unparse(_0x382aae)[a0_0x46a9('0x37')]('\x20')});}['endTask'](_0xb95b4c,_0x27bf0d){let _0x295ea3;if(this['runContext'][a0_0x46a9('0x2f')][_0xb95b4c[a0_0x46a9('0x2')]]){_0x295ea3=this['runContext'][a0_0x46a9('0x2f')][_0xb95b4c[a0_0x46a9('0x2')]];}else{if(this['cacheableOperations'][a0_0x46a9('0x1b')](_0xb95b4c[a0_0x46a9('0x4')][a0_0x46a9('0x4')])>-0x1&&!this['skipNxCache']){_0x295ea3=a0_0x46a9('0x26');}else{_0x295ea3=a0_0x46a9('0x21');}}this[a0_0x46a9('0x2d')](_0xb95b4c,_0x27bf0d,_0x295ea3);}[a0_0x46a9('0x18')](_0x279f0e){for(let _0x2e111f of _0x279f0e){const _0x1b8f90=_0x2e111f[a0_0x46a9('0xb')]==='remote-cache'?'remote-cache-hit':_0x2e111f[a0_0x46a9('0xb')]===a0_0x46a9('0x29')||_0x2e111f[a0_0x46a9('0xb')]===a0_0x46a9('0x0')?a0_0x46a9('0x26'):'cache-miss';this['updateStartedTask'](_0x2e111f['task'],_0x2e111f[a0_0x46a9('0xf')],_0x1b8f90);}}[a0_0x46a9('0x1d')](){}['updateStartedTask'](_0x98f635,_0x5d8187,_0x4882f4){const _0xb6132a=this['tasks'][a0_0x46a9('0x20')](_0x1d3105=>_0x1d3105[a0_0x46a9('0x36')]===_0x98f635['id']);if(!_0xb6132a){throw new Error(a0_0x46a9('0x2e')+_0x98f635['id']);}_0xb6132a[a0_0x46a9('0x8')]=new Date()[a0_0x46a9('0x11')]();_0xb6132a[a0_0x46a9('0xb')]=_0x5d8187;_0xb6132a['params']=this[a0_0x46a9('0x33')][a0_0x46a9('0x1e')](_0xb6132a[a0_0x46a9('0x2a')]);_0xb6132a['cacheStatus']=_0x4882f4;if(this[a0_0x46a9('0x22')]){_0xb6132a['terminalOutput']=this[a0_0x46a9('0x3')](_0x98f635[a0_0x46a9('0x2')],_0xb6132a[a0_0x46a9('0x2b')],_0x5d8187);}}['getTerminalOutput'](_0x10b7fe,_0x2efb5f,_0x3b1f1e){let _0x5e1569;if(this[a0_0x46a9('0x2c')]){if(this[a0_0x46a9('0x2c')][a0_0x46a9('0x7')]('./')){_0x5e1569=(0x0,path_1[a0_0x46a9('0x37')])(appRootPath,this[a0_0x46a9('0x2c')]);}else{_0x5e1569=this[a0_0x46a9('0x2c')];}}else{_0x5e1569=(0x0,path_1['join'])(appRootPath,a0_0x46a9('0xe'),'.cache','nx');}try{const _0x4ecdbe=this['readTerminalOutputFile'](_0x5e1569,_0x10b7fe);const _0x1c9fc0=this[a0_0x46a9('0x33')]['obfuscate'](_0x4ecdbe);if(environment_1['NX_CLOUD_UNLIMITED_OUTPUT'])return _0x1c9fc0;const _0x43c591=_0x2efb5f===a0_0x46a9('0x21')?_0x3b1f1e===0x0?CloudEnabledLifeCycle['MAX_CHARACTERS_SUCCESSFUL_TASK']:CloudEnabledLifeCycle[a0_0x46a9('0x1')]:CloudEnabledLifeCycle[a0_0x46a9('0xc')];return _0x1c9fc0[a0_0x46a9('0x34')]>_0x43c591?a0_0x46a9('0x5')+_0x1c9fc0[a0_0x46a9('0x1a')](_0x1c9fc0[a0_0x46a9('0x34')]-_0x43c591):_0x1c9fc0;}catch(_0x40c383){return'';}}['cleanUpHashDetails'](_0x29c29e){const _0x260d9b={};Object['keys'](_0x29c29e[a0_0x46a9('0x35')])[a0_0x46a9('0x30')](_0x475455=>!_0x475455['startsWith'](a0_0x46a9('0xd')))['forEach'](_0x3b3269=>{_0x260d9b[_0x3b3269]=_0x29c29e['nodes'][_0x3b3269];});return{'nodes':_0x260d9b,'runtime':_0x29c29e[a0_0x46a9('0x24')],'implicitDeps':_0x29c29e[a0_0x46a9('0x25')]};}[a0_0x46a9('0xa')](_0x44956f,_0x448ebc){try{return(0x0,fs_1['readFileSync'])(path[a0_0x46a9('0x37')](_0x44956f,a0_0x46a9('0x28'),_0x448ebc))[a0_0x46a9('0x17')]();}catch(_0x323de6){try{return(0x0,fs_1['readFileSync'])(path[a0_0x46a9('0x37')](_0x44956f,_0x448ebc,a0_0x46a9('0x12')))[a0_0x46a9('0x17')]();}catch(_0x594479){return'';}}}}exports[a0_0x46a9('0x38')]=CloudEnabledLifeCycle;CloudEnabledLifeCycle[a0_0x46a9('0x1')]=0x30d40;CloudEnabledLifeCycle['MAX_CHARACTERS_SUCCESSFUL_TASK']=0x4e20;CloudEnabledLifeCycle[a0_0x46a9('0xc')]=0x4e20; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CloudEnabledLifeCycle = void 0; | ||
const path = require("path"); | ||
const path_1 = require("path"); | ||
const fs_1 = require("fs"); | ||
const environment_1 = require("../../../utilities/environment"); | ||
const { appRootPath, unparse } = require('../../../utilities/nx-imports'); | ||
class CloudEnabledLifeCycle { | ||
constructor(runContext, cacheDirectory, skipNxCache, collectTerminalOutput, cacheableOperations, outputObfuscator, tasks) { | ||
this.runContext = runContext; | ||
this.cacheDirectory = cacheDirectory; | ||
this.skipNxCache = skipNxCache; | ||
this.collectTerminalOutput = collectTerminalOutput; | ||
this.cacheableOperations = cacheableOperations; | ||
this.outputObfuscator = outputObfuscator; | ||
this.tasks = tasks; | ||
} | ||
scheduleTask(task) { | ||
this.runContext.scheduledTasks.push(task); | ||
} | ||
startTask(task) { | ||
const overrides = Object.assign({}, (task.overrides || {})); | ||
if (task.target.configuration) { | ||
overrides['configuration'] = task.target.configuration; | ||
} | ||
this.tasks.push({ | ||
taskId: task.id, | ||
startTime: new Date().toISOString(), | ||
target: task.target.target, | ||
projectName: task.target.project, | ||
hash: task.hash, | ||
hashDetails: this.cleanUpHashDetails(task.hashDetails), | ||
params: unparse(overrides).join(' '), | ||
}); | ||
} | ||
// Used for older version for Nx. Remove in Dec 2022 | ||
endTask(task, code) { | ||
let cacheStatus; | ||
if (this.runContext.statuses[task.hash]) { | ||
cacheStatus = this.runContext.statuses[task.hash]; | ||
} | ||
else { | ||
if (this.cacheableOperations.indexOf(task.target.target) > -1 && | ||
!this.skipNxCache) { | ||
cacheStatus = 'local-cache-hit'; | ||
} | ||
else { | ||
cacheStatus = 'cache-miss'; | ||
} | ||
} | ||
this.updateStartedTask(task, code, cacheStatus); | ||
} | ||
endTasks(tasks) { | ||
for (let t of tasks) { | ||
const status = t.status === 'remote-cache' | ||
? 'remote-cache-hit' | ||
: t.status === 'local-cache' || | ||
t.status === 'local-cache-kept-existing' | ||
? 'local-cache-hit' | ||
: 'cache-miss'; | ||
this.updateStartedTask(t.task, t.code, status); | ||
} | ||
} | ||
endCommand() { } | ||
updateStartedTask(task, code, cacheStatus) { | ||
const startedTask = this.tasks.find((t) => t.taskId === task.id); | ||
if (!startedTask) { | ||
throw new Error(`Cannot find task ${task.id}`); | ||
} | ||
startedTask.endTime = new Date().toISOString(); | ||
startedTask.status = code; | ||
startedTask.params = this.outputObfuscator.obfuscate(startedTask.params); | ||
startedTask.cacheStatus = cacheStatus; | ||
if (this.collectTerminalOutput) { | ||
startedTask.terminalOutput = this.getTerminalOutput(task.hash, startedTask.cacheStatus, code); | ||
} | ||
} | ||
getTerminalOutput(hash, cacheStatus, code) { | ||
let dir; | ||
if (this.cacheDirectory) { | ||
if (this.cacheDirectory.startsWith('./')) { | ||
dir = (0, path_1.join)(appRootPath, this.cacheDirectory); | ||
} | ||
else { | ||
dir = this.cacheDirectory; | ||
} | ||
} | ||
else { | ||
dir = (0, path_1.join)(appRootPath, 'node_modules', '.cache', 'nx'); | ||
} | ||
try { | ||
const taskOutput = this.readTerminalOutputFile(dir, hash); | ||
const taskOutputSanitized = this.outputObfuscator.obfuscate(taskOutput); | ||
if (environment_1.NX_CLOUD_UNLIMITED_OUTPUT) | ||
return taskOutputSanitized; | ||
const maxCharacters = cacheStatus === 'cache-miss' | ||
? code === 0 | ||
? CloudEnabledLifeCycle.MAX_CHARACTERS_SUCCESSFUL_TASK | ||
: CloudEnabledLifeCycle.MAX_CHARACTERS_FAILED_TASK | ||
: CloudEnabledLifeCycle.MAX_CHARACTERS_CACHED_TASK; | ||
return taskOutputSanitized.length > maxCharacters | ||
? `TRUNCATED\n\n${taskOutputSanitized.slice(taskOutputSanitized.length - maxCharacters)}` | ||
: taskOutputSanitized; | ||
} | ||
catch (e) { | ||
return ''; | ||
} | ||
} | ||
cleanUpHashDetails(hashDetails) { | ||
const nodes = {}; | ||
Object.keys(hashDetails.nodes) | ||
.filter((k) => !k.startsWith('npm:')) | ||
.forEach((k) => { | ||
nodes[k] = hashDetails.nodes[k]; | ||
}); | ||
return { | ||
nodes, | ||
runtime: hashDetails.runtime, | ||
implicitDeps: hashDetails.implicitDeps, | ||
}; | ||
} | ||
readTerminalOutputFile(dir, hash) { | ||
try { | ||
return (0, fs_1.readFileSync)(path.join(dir, 'terminalOutputs', hash)).toString(); | ||
} | ||
catch (_a) { | ||
try { | ||
return (0, fs_1.readFileSync)(path.join(dir, hash, 'terminalOutput')).toString(); | ||
} | ||
catch (_b) { | ||
return ''; | ||
} | ||
} | ||
} | ||
} | ||
exports.CloudEnabledLifeCycle = CloudEnabledLifeCycle; | ||
CloudEnabledLifeCycle.MAX_CHARACTERS_FAILED_TASK = 200000; | ||
CloudEnabledLifeCycle.MAX_CHARACTERS_SUCCESSFUL_TASK = 20000; | ||
CloudEnabledLifeCycle.MAX_CHARACTERS_CACHED_TASK = 20000; | ||
//# sourceMappingURL=cloud-enabled-life-cycle.js.map |
@@ -1,1 +0,167 @@ | ||
const a1_0x5309=['../../file-storage/file-storage','DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE','path','anyErrors','getRunGroup','./cloud-run.api','extractGitSha','../../../utilities/metric-logger','join','printCacheHitsMessage','getMachineInfo','forEach','hash','MessageReporter','AGENT_RUNNING_IN_DISTRIBUTED_EXECUTION','toISOString','parseCommand','NX_CLOUD_DISTRIBUTED_EXECUTION_ID','Executed\x20tasks\x20with\x20hashes:\x20','./cloud-enabled-life-cycle','requests','FileStorage','cacheableOperations','all','EndOfRunMessage','__awaiter','note','./cloud-remote-cache','scan','cloudEnabledTasksRunner','exit','error','CloudRunApi','CloudEnabledLifeCycle','submitRunMetrics','../../terminal-output/output-obfuscator','cacheDirectory','defineProperty','maskedProperties','filter','map','complete','apply','next','skipNxCache','endRun','encryptionKey','Agent\x20wasn\x27t\x20able\x20to\x20record\x20its\x20run','__esModule','rxjs/internal/Subject','getBranch','stringify','VERBOSE_LOGGING','Subject','../../terminal-output/end-of-run-message','printMessages','tasks-hashes-','lifeCycle','then','assign','waitForStoreRequestsToComplete','CloudRemoteCache','OutputObfuscator','taskId','value','../../file-storage/e2e-encryption','E2EEncryption','../../../utilities/environment','../../terminal-output/message-reporter','done'];(function(_0x10711b,_0x53098e){const _0x7ae59e=function(_0x29a4bf){while(--_0x29a4bf){_0x10711b['push'](_0x10711b['shift']());}};_0x7ae59e(++_0x53098e);}(a1_0x5309,0xa9));const a1_0x7ae5=function(_0x10711b,_0x53098e){_0x10711b=_0x10711b-0x0;let _0x7ae59e=a1_0x5309[_0x10711b];return _0x7ae59e;};'use strict';var __awaiter=this&&this[a1_0x7ae5('0x42')]||function(_0x269467,_0x1ee7ab,_0x1a710f,_0x5c9121){function _0x14c897(_0x49a8c9){return _0x49a8c9 instanceof _0x1a710f?_0x49a8c9:new _0x1a710f(function(_0x3def0f){_0x3def0f(_0x49a8c9);});}return new(_0x1a710f||(_0x1a710f=Promise))(function(_0x927a55,_0x5f4ab7){function _0x20f2e0(_0x32ec46){try{_0x2c9fb8(_0x5c9121[a1_0x7ae5('0xe')](_0x32ec46));}catch(_0x401bbd){_0x5f4ab7(_0x401bbd);}}function _0x47a7bd(_0x4a6870){try{_0x2c9fb8(_0x5c9121['throw'](_0x4a6870));}catch(_0x4128c0){_0x5f4ab7(_0x4128c0);}}function _0x2c9fb8(_0x4b8b79){_0x4b8b79[a1_0x7ae5('0x28')]?_0x927a55(_0x4b8b79[a1_0x7ae5('0x23')]):_0x14c897(_0x4b8b79['value'])[a1_0x7ae5('0x1d')](_0x20f2e0,_0x47a7bd);}_0x2c9fb8((_0x5c9121=_0x5c9121[a1_0x7ae5('0xd')](_0x269467,_0x1ee7ab||[]))[a1_0x7ae5('0xe')]());});};Object[a1_0x7ae5('0x8')](exports,a1_0x7ae5('0x13'),{'value':!![]});exports[a1_0x7ae5('0x0')]=void 0x0;const Subject_1=require(a1_0x7ae5('0x14'));const message_reporter_1=require(a1_0x7ae5('0x27'));const end_of_run_message_1=require(a1_0x7ae5('0x19'));const output_obfuscator_1=require(a1_0x7ae5('0x6'));const cloud_enabled_life_cycle_1=require(a1_0x7ae5('0x3c'));const file_storage_1=require(a1_0x7ae5('0x29'));const e2e_encryption_1=require(a1_0x7ae5('0x24'));const environment_1=require(a1_0x7ae5('0x26'));const cloud_remote_cache_1=require(a1_0x7ae5('0x44'));const cloud_run_api_1=require(a1_0x7ae5('0x2e'));const fs_1=require('fs');const path=require(a1_0x7ae5('0x2b'));const metric_logger_1=require(a1_0x7ae5('0x30'));const {tasksRunnerV2,output}=require('../../../utilities/nx-imports');function createApi(_0x11dde4,_0x17e6ea,_0x578468){const _0x37ba5f=(0x0,environment_1[a1_0x7ae5('0x33')])(_0x17e6ea);return new cloud_run_api_1[(a1_0x7ae5('0x3'))](_0x11dde4,_0x578468,_0x17e6ea,_0x37ba5f);}function storeTaskHashes(_0x51ad15,_0x427c51,_0xe64b67){const _0x3c5110=JSON[a1_0x7ae5('0x16')](_0x51ad15[a1_0x7ae5('0xb')](_0x3c34ba=>({'taskId':_0x3c34ba[a1_0x7ae5('0x22')],'hash':_0x3c34ba[a1_0x7ae5('0x35')]})));if(environment_1[a1_0x7ae5('0x17')]){output[a1_0x7ae5('0x43')]({'title':a1_0x7ae5('0x3b')+_0x3c5110});}(0x0,fs_1['writeFileSync'])(path[a1_0x7ae5('0x31')](_0x427c51,a1_0x7ae5('0x1b')+_0xe64b67),_0x3c5110);}function onComplete(_0x94a757,_0x1e8ffa,_0x2b1a68,_0x17c81e,_0x206550,_0x1c4f5e,_0x14ec2,_0x33fbc4,_0xa9da88,_0x5bc2ab,_0x1e4335){return __awaiter(this,void 0x0,void 0x0,function*(){const _0xcac456=new Date()[a1_0x7ae5('0x38')]();if(environment_1[a1_0x7ae5('0x37')]){storeTaskHashes(_0xa9da88,_0x1e8ffa[a1_0x7ae5('0x7')]||'./node_modules/.cache/nx',environment_1[a1_0x7ae5('0x3a')]);}const _0x53c1a5=(0x0,environment_1[a1_0x7ae5('0x15')])();const _0x5a757f=yield Promise[a1_0x7ae5('0x40')]([_0x2b1a68[a1_0x7ae5('0x1f')](),_0x17c81e[a1_0x7ae5('0x10')]({'command':_0x206550['obfuscate']((0x0,environment_1[a1_0x7ae5('0x39')])()),'startTime':_0x1c4f5e,'endTime':_0xcac456,'distributedExecutionId':environment_1['NX_CLOUD_DISTRIBUTED_EXECUTION_ID'],'branch':_0x53c1a5,'scan':!![],'runGroup':(0x0,environment_1[a1_0x7ae5('0x2d')])(),'sha':_0x53c1a5?(0x0,environment_1[a1_0x7ae5('0x2f')])():undefined,'inner':_0x1e4335},_0xa9da88)]);if(_0x5bc2ab){setTimeout(()=>{_0x14ec2[a1_0x7ae5('0x1a')]();if(!_0x14ec2[a1_0x7ae5('0x2c')]&&!_0x1e4335){_0x33fbc4[a1_0x7ae5('0x32')]();}},0x0);}else{_0x14ec2[a1_0x7ae5('0x1a')]();if(!_0x14ec2[a1_0x7ae5('0x2c')]&&!_0x1e4335){_0x33fbc4[a1_0x7ae5('0x32')]();}}if(environment_1[a1_0x7ae5('0x37')]){if(!_0x5a757f[0x0]){output[a1_0x7ae5('0x2')]({'title':'Agent\x20wasn\x27t\x20able\x20to\x20store\x20artifacts'});_0x14ec2['printMessages']();process[a1_0x7ae5('0x1')](environment_1[a1_0x7ae5('0x2a')]);}if(!_0x5a757f[0x1]){output['error']({'title':a1_0x7ae5('0x12')});_0x14ec2[a1_0x7ae5('0x1a')]();process[a1_0x7ae5('0x1')](environment_1[a1_0x7ae5('0x2a')]);}}yield(0x0,metric_logger_1[a1_0x7ae5('0x5')])(_0x1e8ffa);});}function createLifeCycle(_0x32934d,_0xeb3467,_0x25161a,_0x60c42){const _0x5b9050=new cloud_enabled_life_cycle_1[(a1_0x7ae5('0x4'))](_0x32934d,_0xeb3467[a1_0x7ae5('0x7')],!!_0xeb3467[a1_0x7ae5('0xf')],_0xeb3467[a1_0x7ae5('0x45')]===undefined?!![]:_0xeb3467['scan'],_0xeb3467[a1_0x7ae5('0x3f')]||[],_0x25161a,_0x60c42);try{const {CompositeLifeCycle}=require('../../../utilities/nx-imports');if(!CompositeLifeCycle)return _0x5b9050;return new CompositeLifeCycle([_0xeb3467['lifeCycle'],_0x5b9050]);}catch(_0x83ae4e){return _0x5b9050;}}function cloudEnabledTasksRunner(_0x5daed6,_0x488450,_0x48f5c9,_0x4bce08=![]){const _0x1c57dd={'statuses':{},'scheduledTasks':[],'requests':{},'allTasks':_0x5daed6};const _0x206223=_0x488450[a1_0x7ae5('0x1c')]===undefined;const _0x2b4243=[];const _0x44ec77=new message_reporter_1[(a1_0x7ae5('0x36'))](_0x488450);const _0x19287e=createApi(_0x44ec77,_0x488450,_0x1c57dd);const _0x550c4d=new end_of_run_message_1[(a1_0x7ae5('0x41'))](_0x1c57dd,_0x2b4243);const _0x535c27=new output_obfuscator_1[(a1_0x7ae5('0x21'))](_0x488450[a1_0x7ae5('0x9')]);const _0x53f608=_0x5daed6[a1_0x7ae5('0xb')](_0x4886ff=>_0x4886ff['hash'])[a1_0x7ae5('0xa')](_0x2cf4c8=>!!_0x2cf4c8);const _0x3e1224=_0x19287e['startRun'](environment_1[a1_0x7ae5('0x3a')],_0x53f608);_0x53f608[a1_0x7ae5('0x34')](_0x360d24=>{_0x1c57dd[a1_0x7ae5('0x3d')][_0x360d24]=_0x3e1224;});const _0x3566aa=new Date()['toISOString']();const _0x182266=createLifeCycle(_0x1c57dd,_0x488450,_0x535c27,_0x2b4243);const _0x24a3b2=new e2e_encryption_1[(a1_0x7ae5('0x25'))](environment_1['ENCRYPTION_KEY']||_0x488450[a1_0x7ae5('0x11')]);const _0x34b4d1=new file_storage_1[(a1_0x7ae5('0x3e'))](_0x24a3b2);const _0x4cc90c=new cloud_remote_cache_1[(a1_0x7ae5('0x20'))](_0x44ec77,_0x19287e,_0x1c57dd,_0x34b4d1);delete process['env'][a1_0x7ae5('0x3a')];const _0x99b6ec=tasksRunnerV2(_0x5daed6,Object[a1_0x7ae5('0x1e')](Object['assign']({},_0x488450),{'remoteCache':_0x4cc90c,'lifeCycle':_0x182266}),_0x48f5c9);if(_0x99b6ec['subscribe']){const _0x289888=new Subject_1[(a1_0x7ae5('0x18'))]();_0x99b6ec['subscribe']({'next':_0x2779d8=>_0x289888[a1_0x7ae5('0xe')](_0x2779d8),'error':_0x339db3=>_0x289888[a1_0x7ae5('0x2')](_0x339db3),'complete':()=>__awaiter(this,void 0x0,void 0x0,function*(){yield onComplete(_0x182266,_0x488450,_0x4cc90c,_0x19287e,_0x535c27,_0x3566aa,_0x44ec77,_0x550c4d,_0x2b4243,_0x206223,_0x4bce08);_0x289888[a1_0x7ae5('0xc')]();})});return _0x289888;}else{return _0x99b6ec[a1_0x7ae5('0x1d')](_0x2a6481=>__awaiter(this,void 0x0,void 0x0,function*(){yield onComplete(_0x182266,_0x488450,_0x4cc90c,_0x19287e,_0x535c27,_0x3566aa,_0x44ec77,_0x550c4d,_0x2b4243,_0x206223,_0x4bce08);return _0x2a6481;}))['catch'](_0x41202e=>__awaiter(this,void 0x0,void 0x0,function*(){yield onComplete(_0x182266,_0x488450,_0x4cc90c,_0x19287e,_0x535c27,_0x3566aa,_0x44ec77,_0x550c4d,_0x2b4243,_0x206223,_0x4bce08);throw _0x41202e;}));}}exports[a1_0x7ae5('0x0')]=cloudEnabledTasksRunner; | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.cloudEnabledTasksRunner = void 0; | ||
const Subject_1 = require("rxjs/internal/Subject"); | ||
const message_reporter_1 = require("../../terminal-output/message-reporter"); | ||
const end_of_run_message_1 = require("../../terminal-output/end-of-run-message"); | ||
const output_obfuscator_1 = require("../../terminal-output/output-obfuscator"); | ||
const cloud_enabled_life_cycle_1 = require("./cloud-enabled-life-cycle"); | ||
const file_storage_1 = require("../../file-storage/file-storage"); | ||
const e2e_encryption_1 = require("../../file-storage/e2e-encryption"); | ||
const environment_1 = require("../../../utilities/environment"); | ||
const cloud_remote_cache_1 = require("./cloud-remote-cache"); | ||
const cloud_run_api_1 = require("./cloud-run.api"); | ||
const fs_1 = require("fs"); | ||
const path = require("path"); | ||
const metric_logger_1 = require("../../../utilities/metric-logger"); | ||
const { tasksRunnerV2, output } = require('../../../utilities/nx-imports'); | ||
function createApi(errors, options, runContext) { | ||
const machineInfo = (0, environment_1.getMachineInfo)(options); | ||
return new cloud_run_api_1.CloudRunApi(errors, runContext, options, machineInfo); | ||
} | ||
function storeTaskHashes(taskExecutions, directory, distributedExecutionId) { | ||
const hashes = JSON.stringify(taskExecutions.map((t) => ({ | ||
taskId: t.taskId, | ||
hash: t.hash, | ||
}))); | ||
if (environment_1.VERBOSE_LOGGING) { | ||
output.note({ | ||
title: `Executed tasks with hashes: ${hashes}`, | ||
}); | ||
} | ||
(0, fs_1.writeFileSync)(path.join(directory, `tasks-hashes-${distributedExecutionId}`), hashes); | ||
} | ||
function onComplete(lifeCycle, options, remoteCache, api, outputObfuscator, runStartTime, messages, endOfRunMessage, taskExecutions, versionOfNxBefore133, inner) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const runEndTime = new Date().toISOString(); | ||
if (environment_1.AGENT_RUNNING_IN_DISTRIBUTED_EXECUTION) { | ||
storeTaskHashes(taskExecutions, options.cacheDirectory || './node_modules/.cache/nx', environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_ID); | ||
} | ||
const branch = (0, environment_1.getBranch)(); | ||
const endRequest = yield Promise.all([ | ||
remoteCache.waitForStoreRequestsToComplete(), | ||
api.endRun({ | ||
command: outputObfuscator.obfuscate((0, environment_1.parseCommand)()), | ||
startTime: runStartTime, | ||
endTime: runEndTime, | ||
distributedExecutionId: environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_ID, | ||
branch: branch, | ||
scan: true, | ||
runGroup: (0, environment_1.getRunGroup)(), | ||
// only set sha if branch is set because we invoke a separate process, | ||
// which adds a few millis | ||
sha: branch ? (0, environment_1.extractGitSha)() : undefined, | ||
inner: inner, | ||
}, taskExecutions), | ||
]); | ||
// this workaround is required because prior to Nx 13.3 we printed | ||
// the end message after the runner completes, so we need to wait for the | ||
// message to appear in the right place | ||
if (versionOfNxBefore133) { | ||
setTimeout(() => { | ||
messages.printMessages(); | ||
if (!messages.anyErrors && !inner) { | ||
endOfRunMessage.printCacheHitsMessage(); | ||
} | ||
}, 0); | ||
} | ||
else { | ||
messages.printMessages(); | ||
if (!messages.anyErrors && !inner) { | ||
endOfRunMessage.printCacheHitsMessage(); | ||
} | ||
} | ||
if (environment_1.AGENT_RUNNING_IN_DISTRIBUTED_EXECUTION) { | ||
if (!endRequest[0]) { | ||
output.error({ | ||
title: `Agent wasn't able to store artifacts`, | ||
}); | ||
messages.printMessages(); | ||
process.exit(environment_1.DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE); | ||
} | ||
if (!endRequest[1]) { | ||
output.error({ | ||
title: `Agent wasn't able to record its run`, | ||
}); | ||
messages.printMessages(); | ||
process.exit(environment_1.DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE); | ||
} | ||
} | ||
yield (0, metric_logger_1.submitRunMetrics)(options); | ||
}); | ||
} | ||
function createLifeCycle(runContext, options, outputObfuscator, tasks) { | ||
const cloudEnabledLifeCycle = new cloud_enabled_life_cycle_1.CloudEnabledLifeCycle(runContext, options.cacheDirectory, !!options.skipNxCache, options.scan === undefined ? true : options.scan, options.cacheableOperations || [], outputObfuscator, tasks); | ||
try { | ||
const { CompositeLifeCycle } = require('../../../utilities/nx-imports'); | ||
if (!CompositeLifeCycle) | ||
return cloudEnabledLifeCycle; | ||
return new CompositeLifeCycle([options.lifeCycle, cloudEnabledLifeCycle]); | ||
} | ||
catch (e) { | ||
return cloudEnabledLifeCycle; | ||
} | ||
} | ||
function cloudEnabledTasksRunner(tasks, options, context, inner = false) { | ||
const runContext = { | ||
statuses: {}, | ||
scheduledTasks: [], | ||
requests: {}, | ||
allTasks: tasks, | ||
}; | ||
const versionOfNxBefore133 = options.lifeCycle === undefined; | ||
const taskExecutions = []; | ||
const messages = new message_reporter_1.MessageReporter(options); | ||
const api = createApi(messages, options, runContext); | ||
const endOfRunMessage = new end_of_run_message_1.EndOfRunMessage(runContext, taskExecutions); | ||
const outputObfuscator = new output_obfuscator_1.OutputObfuscator(options.maskedProperties); | ||
const hashes = tasks.map((t) => t.hash).filter((h) => !!h); | ||
const startRunRequest = api.startRun(environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_ID, hashes); | ||
hashes.forEach((hash) => { | ||
runContext.requests[hash] = startRunRequest; | ||
}); | ||
const runStartTime = new Date().toISOString(); | ||
const lifeCycle = createLifeCycle(runContext, options, outputObfuscator, taskExecutions); | ||
const encryption = new e2e_encryption_1.E2EEncryption(environment_1.ENCRYPTION_KEY || options.encryptionKey); | ||
const fileStorage = new file_storage_1.FileStorage(encryption); | ||
const remoteCache = new cloud_remote_cache_1.CloudRemoteCache(messages, api, runContext, fileStorage); | ||
// have to reset it so we don't capture inner tasks | ||
delete process.env.NX_CLOUD_DISTRIBUTED_EXECUTION_ID; | ||
const res = tasksRunnerV2(tasks, Object.assign(Object.assign({}, options), { remoteCache, lifeCycle }), context); | ||
// observable -> legacy | ||
if (res.subscribe) { | ||
const wrappedRes = new Subject_1.Subject(); | ||
res.subscribe({ | ||
next: (value) => wrappedRes.next(value), | ||
error: (err) => wrappedRes.error(err), | ||
complete: () => __awaiter(this, void 0, void 0, function* () { | ||
yield onComplete(lifeCycle, options, remoteCache, api, outputObfuscator, runStartTime, messages, endOfRunMessage, taskExecutions, versionOfNxBefore133, inner); | ||
wrappedRes.complete(); | ||
}), | ||
}); | ||
return wrappedRes; | ||
// promise | ||
} | ||
else { | ||
return res | ||
.then((r) => __awaiter(this, void 0, void 0, function* () { | ||
yield onComplete(lifeCycle, options, remoteCache, api, outputObfuscator, runStartTime, messages, endOfRunMessage, taskExecutions, versionOfNxBefore133, inner); | ||
return r; | ||
})) | ||
.catch((e) => __awaiter(this, void 0, void 0, function* () { | ||
yield onComplete(lifeCycle, options, remoteCache, api, outputObfuscator, runStartTime, messages, endOfRunMessage, taskExecutions, versionOfNxBefore133, inner); | ||
throw e; | ||
})); | ||
} | ||
} | ||
exports.cloudEnabledTasksRunner = cloudEnabledTasksRunner; | ||
//# sourceMappingURL=cloud-enabled.runner.js.map |
@@ -1,1 +0,113 @@ | ||
const a2_0x21ea=['map','api','runContext','fileStorage','VERBOSE_LOGGING','defineProperty','messages','retrieve','put','NX_CLOUD_DISTRIBUTED_EXECUTION_ID','../../../utilities/environment','.\x20Status\x20404.','value','__awaiter','hashUrls','requests','__esModule','status','storage','statuses','note','storeRequests','remote-cache-hit','store','apply','hash','waitForStoreRequestsToComplete','cacheError','axiosException','get','extractErrorMessage','reduce','then','next','response','Nx\x20Cloud:\x20Skipping\x20storing\x20','.\x20Read\x20only\x20token\x20is\x20used.','all','CloudRemoteCache','Nx\x20Cloud:\x20Cache\x20miss\x20'];(function(_0x4b8d6a,_0x21eafb){const _0x55112c=function(_0x2c4c21){while(--_0x2c4c21){_0x4b8d6a['push'](_0x4b8d6a['shift']());}};_0x55112c(++_0x21eafb);}(a2_0x21ea,0x1a1));const a2_0x5511=function(_0x4b8d6a,_0x21eafb){_0x4b8d6a=_0x4b8d6a-0x0;let _0x55112c=a2_0x21ea[_0x4b8d6a];return _0x55112c;};'use strict';var __awaiter=this&&this[a2_0x5511('0x24')]||function(_0x1bf809,_0x167b0e,_0xd3c674,_0x57f4e6){function _0x4412e4(_0x34d058){return _0x34d058 instanceof _0xd3c674?_0x34d058:new _0xd3c674(function(_0xebb755){_0xebb755(_0x34d058);});}return new(_0xd3c674||(_0xd3c674=Promise))(function(_0x28e19c,_0x1ea122){function _0x17a3d6(_0x48bae0){try{_0x157889(_0x57f4e6[a2_0x5511('0x10')](_0x48bae0));}catch(_0x2c37ef){_0x1ea122(_0x2c37ef);}}function _0x2d59a1(_0x631ba0){try{_0x157889(_0x57f4e6['throw'](_0x631ba0));}catch(_0x42c110){_0x1ea122(_0x42c110);}}function _0x157889(_0x535f15){_0x535f15['done']?_0x28e19c(_0x535f15[a2_0x5511('0x23')]):_0x4412e4(_0x535f15[a2_0x5511('0x23')])[a2_0x5511('0xf')](_0x17a3d6,_0x2d59a1);}_0x157889((_0x57f4e6=_0x57f4e6[a2_0x5511('0x7')](_0x1bf809,_0x167b0e||[]))['next']());});};Object[a2_0x5511('0x1c')](exports,a2_0x5511('0x27'),{'value':!![]});exports['CloudRemoteCache']=void 0x0;const environment_1=require(a2_0x5511('0x21'));const {output}=require('../../../utilities/nx-imports');class CloudRemoteCache{constructor(_0x43f47f,_0x454bf4,_0x14d8bc,_0x5503a0){this['messages']=_0x43f47f;this[a2_0x5511('0x18')]=_0x454bf4;this[a2_0x5511('0x19')]=_0x14d8bc;this[a2_0x5511('0x1a')]=_0x5503a0;this[a2_0x5511('0x4')]=[];}[a2_0x5511('0x1e')](_0x103e7b,_0x1b922b){var _0x410038;return __awaiter(this,void 0x0,void 0x0,function*(){if(this[a2_0x5511('0x1d')][a2_0x5511('0xa')])return![];const _0x54935e=yield this['hashUrls'](_0x103e7b);if(!_0x54935e||!_0x54935e[a2_0x5511('0xc')]){if(environment_1[a2_0x5511('0x1b')]){output[a2_0x5511('0x3')]({'title':a2_0x5511('0x16')+_0x103e7b+'.'});}this[a2_0x5511('0x19')][a2_0x5511('0x2')][_0x103e7b]='cache-miss';return![];}try{yield this[a2_0x5511('0x1a')][a2_0x5511('0x1e')](_0x103e7b,_0x54935e[a2_0x5511('0xc')],_0x1b922b);this[a2_0x5511('0x19')][a2_0x5511('0x2')][_0x103e7b]=a2_0x5511('0x5');return!![];}catch(_0x546f41){const _0x5b6743=(_0x410038=_0x546f41[a2_0x5511('0xb')])!==null&&_0x410038!==void 0x0?_0x410038:_0x546f41;if(_0x5b6743[a2_0x5511('0x11')]&&_0x5b6743['response'][a2_0x5511('0x0')]===0x194){if(environment_1[a2_0x5511('0x1b')]){output['note']({'title':a2_0x5511('0x16')+_0x103e7b+a2_0x5511('0x22')});}}else{this[a2_0x5511('0x1d')][a2_0x5511('0xa')]=this['messages'][a2_0x5511('0xd')](_0x5b6743,a2_0x5511('0x1'));}this[a2_0x5511('0x19')][a2_0x5511('0x2')][_0x103e7b]='cache-miss';return![];}});}[a2_0x5511('0x6')](_0x3e6aa6,_0x30ff97){return __awaiter(this,void 0x0,void 0x0,function*(){if(this[a2_0x5511('0x1d')][a2_0x5511('0xa')])return![];const _0x49ff5a=Promise['resolve']()[a2_0x5511('0xf')](()=>__awaiter(this,void 0x0,void 0x0,function*(){var _0x14f3f6;const _0x56cd0e=yield this[a2_0x5511('0x25')](_0x3e6aa6);if(!_0x56cd0e)return![];if(!_0x56cd0e[a2_0x5511('0x1f')]){if(environment_1['VERBOSE_LOGGING']){output[a2_0x5511('0x3')]({'title':a2_0x5511('0x12')+_0x3e6aa6+a2_0x5511('0x13')});}return!![];}try{yield this['fileStorage'][a2_0x5511('0x6')](_0x3e6aa6,_0x56cd0e['put'],_0x30ff97);return!![];}catch(_0x381b1d){const _0x367559=(_0x14f3f6=_0x381b1d[a2_0x5511('0xb')])!==null&&_0x14f3f6!==void 0x0?_0x14f3f6:_0x381b1d;this[a2_0x5511('0x1d')][a2_0x5511('0xa')]=this['messages'][a2_0x5511('0xd')](_0x367559,'storage');return![];}}));this[a2_0x5511('0x4')]['push'](_0x49ff5a);return _0x49ff5a;});}[a2_0x5511('0x25')](_0xe7bc6b){return __awaiter(this,void 0x0,void 0x0,function*(){if(_0xe7bc6b in this[a2_0x5511('0x19')][a2_0x5511('0x26')]){return(yield this[a2_0x5511('0x19')]['requests'][_0xe7bc6b])[_0xe7bc6b];}else{const _0x5609c7=this[a2_0x5511('0x19')]['scheduledTasks']['filter'](_0x2fc2ed=>!this[a2_0x5511('0x19')]['requests'][_0x2fc2ed[a2_0x5511('0x8')]])[a2_0x5511('0x17')](_0x48108c=>_0x48108c[a2_0x5511('0x8')]);if(_0x5609c7['indexOf'](_0xe7bc6b)===-0x1){_0x5609c7['push'](_0xe7bc6b);}const _0x4261f4=this[a2_0x5511('0x18')]['startRun'](environment_1[a2_0x5511('0x20')],_0x5609c7);_0x5609c7['forEach'](_0x2a617e=>{this['runContext'][a2_0x5511('0x26')][_0x2a617e]=_0x4261f4;});return(yield _0x4261f4)[_0xe7bc6b];}});}[a2_0x5511('0x9')](){return Promise[a2_0x5511('0x14')](this[a2_0x5511('0x4')])[a2_0x5511('0xf')](_0x1752d8=>_0x1752d8[a2_0x5511('0xe')]((_0x1f004d,_0x5bddd1)=>_0x1f004d&&_0x5bddd1,!![]));}}exports[a2_0x5511('0x15')]=CloudRemoteCache; | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CloudRemoteCache = void 0; | ||
const environment_1 = require("../../../utilities/environment"); | ||
const { output } = require('../../../utilities/nx-imports'); | ||
class CloudRemoteCache { | ||
constructor(messages, api, runContext, fileStorage) { | ||
this.messages = messages; | ||
this.api = api; | ||
this.runContext = runContext; | ||
this.fileStorage = fileStorage; | ||
this.storeRequests = []; | ||
} | ||
retrieve(hash, cacheDirectory) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.messages.cacheError) | ||
return false; | ||
const hashUrls = yield this.hashUrls(hash); | ||
if (!hashUrls || !hashUrls.get) { | ||
if (environment_1.VERBOSE_LOGGING) { | ||
output.note({ title: `Nx Cloud: Cache miss ${hash}.` }); | ||
} | ||
this.runContext.statuses[hash] = 'cache-miss'; | ||
return false; | ||
} | ||
try { | ||
yield this.fileStorage.retrieve(hash, hashUrls.get, cacheDirectory); | ||
this.runContext.statuses[hash] = 'remote-cache-hit'; | ||
return true; | ||
} | ||
catch (ee) { | ||
const e = (_a = ee.axiosException) !== null && _a !== void 0 ? _a : ee; | ||
if (e.response && e.response.status === 404) { | ||
if (environment_1.VERBOSE_LOGGING) { | ||
output.note({ title: `Nx Cloud: Cache miss ${hash}. Status 404.` }); | ||
} | ||
// cache miss. print nothing | ||
} | ||
else { | ||
this.messages.cacheError = this.messages.extractErrorMessage(e, 'storage'); | ||
} | ||
this.runContext.statuses[hash] = 'cache-miss'; | ||
return false; | ||
} | ||
}); | ||
} | ||
store(hash, cacheDirectory) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.messages.cacheError) | ||
return false; | ||
const res = Promise.resolve().then(() => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
const hashUrls = yield this.hashUrls(hash); | ||
if (!hashUrls) | ||
return false; | ||
if (!hashUrls.put) { | ||
if (environment_1.VERBOSE_LOGGING) { | ||
output.note({ | ||
title: `Nx Cloud: Skipping storing ${hash}. Read only token is used.`, | ||
}); | ||
} | ||
return true; | ||
} | ||
try { | ||
yield this.fileStorage.store(hash, hashUrls.put, cacheDirectory); | ||
return true; | ||
} | ||
catch (ee) { | ||
const e = (_a = ee.axiosException) !== null && _a !== void 0 ? _a : ee; | ||
this.messages.cacheError = this.messages.extractErrorMessage(e, 'storage'); | ||
return false; | ||
} | ||
})); | ||
this.storeRequests.push(res); | ||
return res; | ||
}); | ||
} | ||
hashUrls(hash) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (hash in this.runContext.requests) { | ||
return (yield this.runContext.requests[hash])[hash]; | ||
} | ||
else { | ||
const scheduledTaskHashesWithoutRequests = this.runContext.scheduledTasks | ||
.filter((t) => !this.runContext.requests[t.hash]) | ||
.map((t) => t.hash); | ||
if (scheduledTaskHashesWithoutRequests.indexOf(hash) === -1) { | ||
scheduledTaskHashesWithoutRequests.push(hash); | ||
} | ||
const request = this.api.startRun(environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_ID, scheduledTaskHashesWithoutRequests); | ||
scheduledTaskHashesWithoutRequests.forEach((taskHash) => { | ||
this.runContext.requests[taskHash] = request; | ||
}); | ||
return (yield request)[hash]; | ||
} | ||
}); | ||
} | ||
waitForStoreRequestsToComplete() { | ||
return Promise.all(this.storeRequests).then((r) => r.reduce((a, b) => a && b, true)); | ||
} | ||
} | ||
exports.CloudRemoteCache = CloudRemoteCache; | ||
//# sourceMappingURL=cloud-remote-cache.js.map |
@@ -1,1 +0,158 @@ | ||
const a3_0xb113=['Invalid\x20Nx\x20Cloud\x20response:\x20','defaults','throw','post','../../../utilities/axios','stringify','next','application/octet-stream','__awaiter','slice','startRun','from','success','/nx-cloud/runs/start','/nx-cloud/runs/end','terminalOutput','devDependencies','axiosMultipleTries','message','createApiAxiosInstance','CloudRunApi','readFileSync','done','headers','apply','Invalid\x20end\x20run\x20response:\x20','unknown','promisify','mapRespToPerfEntry','api','urls','runContext','axiosException','RUNNER_FAILURE_PERF_ENTRY','package.json','...','Nx\x20Cloud:\x20Unknown\x20Error\x20Occurred','__esModule','response','../../../utilities/environment','defineProperty','RunEnd.\x20Completed\x20tasks','Run\x20completion\x20responded\x20with\x20`undefined`.','Stack\x20Trace:','RunStart','machineInfo','getBranch','error','apiAxiosInstance','nxCloudVersion','extractErrorMessage','data','gzip','../../../utilities/nx-imports','map','runUrl','apiError','value','string','VERBOSE_LOGGING','status','recordMetric','createMetricRecorder','endRun','util','messages','assign'];(function(_0x3baf84,_0xb11336){const _0x2876bf=function(_0x45cd6b){while(--_0x45cd6b){_0x3baf84['push'](_0x3baf84['shift']());}};_0x2876bf(++_0xb11336);}(a3_0xb113,0x15e));const a3_0x2876=function(_0x3baf84,_0xb11336){_0x3baf84=_0x3baf84-0x0;let _0x2876bf=a3_0xb113[_0x3baf84];return _0x2876bf;};'use strict';var __awaiter=this&&this[a3_0x2876('0x3c')]||function(_0x56e9df,_0x13e104,_0x98cba1,_0x4014b7){function _0x23bfa8(_0x23a1a4){return _0x23a1a4 instanceof _0x98cba1?_0x23a1a4:new _0x98cba1(function(_0x3c49c1){_0x3c49c1(_0x23a1a4);});}return new(_0x98cba1||(_0x98cba1=Promise))(function(_0x5a8b64,_0xec760e){function _0x2ad010(_0x282f14){try{_0x5e7613(_0x4014b7[a3_0x2876('0x3a')](_0x282f14));}catch(_0x150f93){_0xec760e(_0x150f93);}}function _0x395029(_0x3525c8){try{_0x5e7613(_0x4014b7[a3_0x2876('0x36')](_0x3525c8));}catch(_0x5a8609){_0xec760e(_0x5a8609);}}function _0x5e7613(_0x250393){_0x250393[a3_0x2876('0x7')]?_0x5a8b64(_0x250393['value']):_0x23bfa8(_0x250393[a3_0x2876('0x2a')])['then'](_0x2ad010,_0x395029);}_0x5e7613((_0x4014b7=_0x4014b7[a3_0x2876('0x9')](_0x56e9df,_0x13e104||[]))[a3_0x2876('0x3a')]());});};Object[a3_0x2876('0x19')](exports,a3_0x2876('0x16'),{'value':!![]});exports['CloudRunApi']=void 0x0;const axios_1=require(a3_0x2876('0x38'));const environment_1=require(a3_0x2876('0x18'));const fs_1=require('fs');const zlib_1=require('zlib');const util_1=require(a3_0x2876('0x31'));const metric_logger_1=require('../../../utilities/metric-logger');const {output}=require(a3_0x2876('0x26'));class CloudRunApi{constructor(_0x52a1b7,_0x1c95f2,_0x5c4ed4,_0x20ae62){this[a3_0x2876('0x32')]=_0x52a1b7;this[a3_0x2876('0x10')]=_0x1c95f2;this[a3_0x2876('0x1e')]=_0x20ae62;this[a3_0x2876('0x21')]=(0x0,axios_1[a3_0x2876('0x4')])(_0x5c4ed4);}[a3_0x2876('0x3e')](_0x33de87,_0x5455d2){var _0x33c726;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x8059d9=(0x0,metric_logger_1[a3_0x2876('0x2f')])(a3_0x2876('0x3e'));try{const _0x306c93={'meta':{'nxCloudVersion':this['nxCloudVersion']()},'branch':(0x0,environment_1[a3_0x2876('0x1f')])(),'runGroup':(0x0,environment_1['getRunGroup'])(),'distributedExecutionId':_0x33de87,'hashes':_0x5455d2};if(environment_1[a3_0x2876('0x2c')]){output['note']({'title':a3_0x2876('0x1d'),'bodyLines':['\x0a'+JSON[a3_0x2876('0x39')](_0x306c93,null,0x2)]});}const _0x1e1633=yield(0x0,axios_1[a3_0x2876('0x2')])(()=>this[a3_0x2876('0x21')][a3_0x2876('0x37')](a3_0x2876('0x41'),_0x306c93));_0x8059d9[a3_0x2876('0x2e')]((0x0,metric_logger_1[a3_0x2876('0xd')])(_0x1e1633));if(_0x1e1633[a3_0x2876('0x24')]&&_0x1e1633[a3_0x2876('0x24')]['message']){this[a3_0x2876('0x32')][a3_0x2876('0x3')]=_0x1e1633[a3_0x2876('0x24')]['message'];}if(!_0x1e1633[a3_0x2876('0x24')]||!_0x1e1633['data'][a3_0x2876('0xf')]){this[a3_0x2876('0x32')][a3_0x2876('0x29')]=a3_0x2876('0x34')+JSON[a3_0x2876('0x39')](_0x1e1633[a3_0x2876('0x24')]);return{};}return _0x1e1633[a3_0x2876('0x24')][a3_0x2876('0xf')];}catch(_0x124fb2){_0x8059d9[a3_0x2876('0x2e')](((_0x33c726=_0x124fb2===null||_0x124fb2===void 0x0?void 0x0:_0x124fb2[a3_0x2876('0x11')])===null||_0x33c726===void 0x0?void 0x0:_0x33c726[a3_0x2876('0x17')])?(0x0,metric_logger_1[a3_0x2876('0xd')])(_0x124fb2[a3_0x2876('0x11')]['response']):metric_logger_1[a3_0x2876('0x12')]);this[a3_0x2876('0x32')][a3_0x2876('0x29')]=this[a3_0x2876('0x32')]['extractErrorMessage'](_0x124fb2,a3_0x2876('0xe'));return{};}});}[a3_0x2876('0x30')](_0x2fd223,_0x4ea7db){var _0x25b97e,_0x15863a;return __awaiter(this,void 0x0,void 0x0,function*(){if(this[a3_0x2876('0x32')][a3_0x2876('0x29')])return![];const _0x2d8e8b={'meta':{'nxCloudVersion':this[a3_0x2876('0x22')]()},'tasks':_0x4ea7db,'run':_0x2fd223,'machineInfo':this[a3_0x2876('0x1e')]};const _0x315244=Buffer[a3_0x2876('0x3f')](JSON[a3_0x2876('0x39')](_0x2d8e8b));const _0x147342=yield(0x0,util_1[a3_0x2876('0xc')])(zlib_1[a3_0x2876('0x25')])(_0x315244);const _0x262a5e=(0x0,metric_logger_1[a3_0x2876('0x2f')])(a3_0x2876('0x30'));try{if(environment_1[a3_0x2876('0x2c')]){const _0x1a78f0=_0x4ea7db[a3_0x2876('0x27')](_0x5f2f50=>{return Object[a3_0x2876('0x33')](Object['assign']({},_0x5f2f50),{'terminalOutput':_0x5f2f50['terminalOutput']?_0x5f2f50[a3_0x2876('0x0')][a3_0x2876('0x3d')](0x0,0x14)+a3_0x2876('0x14'):undefined});});output['note']({'title':a3_0x2876('0x1a'),'bodyLines':['\x0a'+JSON[a3_0x2876('0x39')](_0x1a78f0,null,0x2)]});}const _0x1edb6a=yield(0x0,axios_1['axiosMultipleTries'])(()=>this[a3_0x2876('0x21')][a3_0x2876('0x37')](a3_0x2876('0x42'),_0x147342,{'headers':Object[a3_0x2876('0x33')](Object['assign']({},this[a3_0x2876('0x21')][a3_0x2876('0x35')][a3_0x2876('0x8')]),{'Content-Encoding':'gzip','Content-Type':a3_0x2876('0x3b')})}));if(_0x1edb6a){_0x262a5e[a3_0x2876('0x2e')]((0x0,metric_logger_1['mapRespToPerfEntry'])(_0x1edb6a));if(_0x1edb6a['data']&&_0x1edb6a['data'][a3_0x2876('0x28')]&&_0x1edb6a[a3_0x2876('0x24')][a3_0x2876('0x2d')]===a3_0x2876('0x40')){this[a3_0x2876('0x10')][a3_0x2876('0x28')]=_0x1edb6a[a3_0x2876('0x24')][a3_0x2876('0x28')];return!![];}if(_0x1edb6a[a3_0x2876('0x24')]&&_0x1edb6a['data'][a3_0x2876('0x2d')]){this[a3_0x2876('0x32')][a3_0x2876('0x29')]=a3_0x2876('0xa')+JSON[a3_0x2876('0x39')](_0x1edb6a[a3_0x2876('0x24')][a3_0x2876('0x3')]);}else if(_0x1edb6a[a3_0x2876('0x24')]&&typeof _0x1edb6a[a3_0x2876('0x24')]===a3_0x2876('0x2b')){if(_0x1edb6a[a3_0x2876('0x24')]!==a3_0x2876('0x40')){this['messages'][a3_0x2876('0x29')]='Invalid\x20end\x20run\x20response:\x20'+JSON['stringify'](_0x1edb6a[a3_0x2876('0x24')]);}}else{this[a3_0x2876('0x32')][a3_0x2876('0x29')]='Invalid\x20end\x20run\x20response:\x20'+JSON['stringify'](_0x1edb6a[a3_0x2876('0x24')]);}if(environment_1[a3_0x2876('0x2c')]){output['note']({'title':'Invalid\x20end\x20run\x20response','bodyLines':[JSON[a3_0x2876('0x39')](_0x1edb6a[a3_0x2876('0x24')],null,0x2)]});}}else{output[a3_0x2876('0x20')]({'title':a3_0x2876('0x15'),'bodyLines':[a3_0x2876('0x1b'),'Run\x20Details:',JSON[a3_0x2876('0x39')](_0x2fd223,null,0x2),a3_0x2876('0x1c'),JSON[a3_0x2876('0x39')](new Error()['stack'],null,0x2)]});}return![];}catch(_0xdb202a){_0x262a5e['recordMetric'](((_0x25b97e=_0xdb202a===null||_0xdb202a===void 0x0?void 0x0:_0xdb202a[a3_0x2876('0x11')])===null||_0x25b97e===void 0x0?void 0x0:_0x25b97e['response'])?(0x0,metric_logger_1[a3_0x2876('0xd')])(_0xdb202a['axiosException']['response']):metric_logger_1['RUNNER_FAILURE_PERF_ENTRY']);const _0x4b6856=(_0x15863a=_0xdb202a[a3_0x2876('0x11')])!==null&&_0x15863a!==void 0x0?_0x15863a:_0xdb202a;this[a3_0x2876('0x32')][a3_0x2876('0x29')]=this[a3_0x2876('0x32')][a3_0x2876('0x23')](_0x4b6856,a3_0x2876('0xe'));return![];}});}[a3_0x2876('0x22')](){try{const _0xdabd82=JSON['parse']((0x0,fs_1[a3_0x2876('0x6')])(a3_0x2876('0x13'))['toString']());return _0xdabd82[a3_0x2876('0x1')]['@nrwl/nx-cloud'];}catch(_0x13159c){return a3_0x2876('0xb');}}}exports[a3_0x2876('0x5')]=CloudRunApi; | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CloudRunApi = void 0; | ||
const axios_1 = require("../../../utilities/axios"); | ||
const environment_1 = require("../../../utilities/environment"); | ||
const fs_1 = require("fs"); | ||
const zlib_1 = require("zlib"); | ||
const util_1 = require("util"); | ||
const metric_logger_1 = require("../../../utilities/metric-logger"); | ||
const { output } = require('../../../utilities/nx-imports'); | ||
class CloudRunApi { | ||
constructor(messages, runContext, options, machineInfo) { | ||
this.messages = messages; | ||
this.runContext = runContext; | ||
this.machineInfo = machineInfo; | ||
this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options); | ||
} | ||
startRun(distributedExecutionId, hashes) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const recorder = (0, metric_logger_1.createMetricRecorder)('startRun'); | ||
try { | ||
const request = { | ||
meta: { | ||
nxCloudVersion: this.nxCloudVersion(), | ||
}, | ||
branch: (0, environment_1.getBranch)(), | ||
runGroup: (0, environment_1.getRunGroup)(), | ||
distributedExecutionId, | ||
hashes, | ||
}; | ||
if (environment_1.VERBOSE_LOGGING) { | ||
output.note({ | ||
title: 'RunStart', | ||
bodyLines: ['\n' + JSON.stringify(request, null, 2)], | ||
}); | ||
} | ||
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/runs/start', request)); | ||
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp)); | ||
if (resp.data && resp.data.message) { | ||
this.messages.message = resp.data.message; | ||
} | ||
if (!resp.data || !resp.data.urls) { | ||
this.messages.apiError = `Invalid Nx Cloud response: ${JSON.stringify(resp.data)}`; | ||
return {}; | ||
} | ||
return resp.data.urls; | ||
} | ||
catch (e) { | ||
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response) | ||
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response) | ||
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY); | ||
this.messages.apiError = this.messages.extractErrorMessage(e, 'api'); | ||
return {}; | ||
} | ||
}); | ||
} | ||
endRun(run, tasks) { | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// API is not working, don't make the end request | ||
if (this.messages.apiError) | ||
return false; | ||
const uncompressedReqBody = { | ||
meta: { | ||
nxCloudVersion: this.nxCloudVersion(), | ||
}, | ||
tasks, | ||
run: run, | ||
machineInfo: this.machineInfo, | ||
}; | ||
const uncompressedBuffer = Buffer.from(JSON.stringify(uncompressedReqBody)); | ||
const compressedBuffer = yield (0, util_1.promisify)(zlib_1.gzip)(uncompressedBuffer); | ||
const recorder = (0, metric_logger_1.createMetricRecorder)('endRun'); | ||
try { | ||
if (environment_1.VERBOSE_LOGGING) { | ||
const t = tasks.map((tt) => { | ||
return Object.assign(Object.assign({}, tt), { terminalOutput: tt.terminalOutput | ||
? `${tt.terminalOutput.slice(0, 20)}...` | ||
: undefined }); | ||
}); | ||
output.note({ | ||
title: 'RunEnd. Completed tasks', | ||
bodyLines: ['\n' + JSON.stringify(t, null, 2)], | ||
}); | ||
} | ||
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/runs/end', compressedBuffer, { | ||
headers: Object.assign(Object.assign({}, this.apiAxiosInstance.defaults.headers), { 'Content-Encoding': 'gzip', 'Content-Type': 'application/octet-stream' }), | ||
})); | ||
if (resp) { | ||
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp)); | ||
if (resp.data && resp.data.runUrl && resp.data.status === 'success') { | ||
this.runContext.runUrl = resp.data.runUrl; | ||
return true; | ||
} | ||
if (resp.data && resp.data.status) { | ||
this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data.message)}`; | ||
} | ||
else if (resp.data && typeof resp.data === 'string') { | ||
if (resp.data !== 'success') { | ||
this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data)}`; | ||
} | ||
} | ||
else { | ||
this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data)}`; | ||
} | ||
if (environment_1.VERBOSE_LOGGING) { | ||
output.note({ | ||
title: 'Invalid end run response', | ||
bodyLines: [JSON.stringify(resp.data, null, 2)], | ||
}); | ||
} | ||
} | ||
else { | ||
output.error({ | ||
title: 'Nx Cloud: Unknown Error Occurred', | ||
bodyLines: [ | ||
'Run completion responded with `undefined`.', | ||
'Run Details:', | ||
JSON.stringify(run, null, 2), | ||
'Stack Trace:', | ||
JSON.stringify(new Error().stack, null, 2), | ||
], | ||
}); | ||
} | ||
return false; | ||
} | ||
catch (ee) { | ||
recorder.recordMetric(((_a = ee === null || ee === void 0 ? void 0 : ee.axiosException) === null || _a === void 0 ? void 0 : _a.response) | ||
? (0, metric_logger_1.mapRespToPerfEntry)(ee.axiosException.response) | ||
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY); | ||
const e = (_b = ee.axiosException) !== null && _b !== void 0 ? _b : ee; | ||
this.messages.apiError = this.messages.extractErrorMessage(e, 'api'); | ||
return false; | ||
} | ||
}); | ||
} | ||
nxCloudVersion() { | ||
try { | ||
const v = JSON.parse((0, fs_1.readFileSync)(`package.json`).toString()); | ||
return v.devDependencies['@nrwl/nx-cloud']; | ||
} | ||
catch (e) { | ||
return 'unknown'; | ||
} | ||
} | ||
} | ||
exports.CloudRunApi = CloudRunApi; | ||
//# sourceMappingURL=cloud-run.api.js.map |
@@ -1,1 +0,79 @@ | ||
const a4_0xdd55=['RUNNER_FAILURE_PERF_ENTRY','Completed\x20run\x20group\x20with\x20an\x20error','../../../utilities/metric-logger','mapRespToPerfEntry','then','VERBOSE_LOGGING','recordMetric','apply','tasks','done','Completing\x20run\x20group\x20with\x20an\x20error','runGroup:\x20','throw','__esModule','__awaiter','createMetricRecorder','axiosException','error','completeRunGroupWithError','response','DistributedAgentApi','error:\x20','apiAxiosInstance','next','note','post','../../../utilities/axios','value','runGroup','agentName'];(function(_0xcbbe07,_0xdd5510){const _0x2174aa=function(_0x3e344e){while(--_0x3e344e){_0xcbbe07['push'](_0xcbbe07['shift']());}};_0x2174aa(++_0xdd5510);}(a4_0xdd55,0x99));const a4_0x2174=function(_0xcbbe07,_0xdd5510){_0xcbbe07=_0xcbbe07-0x0;let _0x2174aa=a4_0xdd55[_0xcbbe07];return _0x2174aa;};'use strict';var __awaiter=this&&this[a4_0x2174('0xb')]||function(_0x123dba,_0x17b178,_0x537fb4,_0x701baf){function _0x1404e0(_0x374662){return _0x374662 instanceof _0x537fb4?_0x374662:new _0x537fb4(function(_0x48c053){_0x48c053(_0x374662);});}return new(_0x537fb4||(_0x537fb4=Promise))(function(_0x20a856,_0x40940d){function _0x49a877(_0x2fbca6){try{_0x14c7a7(_0x701baf[a4_0x2174('0x14')](_0x2fbca6));}catch(_0x375193){_0x40940d(_0x375193);}}function _0x3d8dd9(_0x2e2109){try{_0x14c7a7(_0x701baf[a4_0x2174('0x9')](_0x2e2109));}catch(_0x1fcfec){_0x40940d(_0x1fcfec);}}function _0x14c7a7(_0xc463ca){_0xc463ca[a4_0x2174('0x6')]?_0x20a856(_0xc463ca[a4_0x2174('0x18')]):_0x1404e0(_0xc463ca[a4_0x2174('0x18')])[a4_0x2174('0x1')](_0x49a877,_0x3d8dd9);}_0x14c7a7((_0x701baf=_0x701baf[a4_0x2174('0x4')](_0x123dba,_0x17b178||[]))[a4_0x2174('0x14')]());});};Object['defineProperty'](exports,a4_0x2174('0xa'),{'value':!![]});exports[a4_0x2174('0x11')]=void 0x0;const axios_1=require(a4_0x2174('0x17'));const environment_1=require('../../../utilities/environment');const metric_logger_1=require(a4_0x2174('0x1d'));const {output}=require('../../../utilities/nx-imports');class DistributedAgentApi{constructor(_0x36fc10,_0x25661a,_0x1784ae){this[a4_0x2174('0x19')]=_0x25661a;this[a4_0x2174('0x1a')]=_0x1784ae;this[a4_0x2174('0x13')]=(0x0,axios_1['createApiAxiosInstance'])(_0x36fc10);}[a4_0x2174('0x5')](_0x2e34ad,_0x41f58b,_0x555da2){var _0x4b398d;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x39830d=(0x0,metric_logger_1[a4_0x2174('0xc')])('dtePollTasks');try{const _0x2ae6db=yield(0x0,axios_1['axiosMultipleTries'])(()=>this['apiAxiosInstance'][a4_0x2174('0x16')]('/nx-cloud/executions/tasks',{'runGroup':this[a4_0x2174('0x19')],'agentName':this[a4_0x2174('0x1a')],'executionId':_0x2e34ad,'statusCode':_0x41f58b,'completedTasks':_0x555da2}));_0x39830d[a4_0x2174('0x3')]((0x0,metric_logger_1[a4_0x2174('0x0')])(_0x2ae6db));return _0x2ae6db['data'];}catch(_0x2cbc04){_0x39830d[a4_0x2174('0x3')](((_0x4b398d=_0x2cbc04===null||_0x2cbc04===void 0x0?void 0x0:_0x2cbc04[a4_0x2174('0xd')])===null||_0x4b398d===void 0x0?void 0x0:_0x4b398d['response'])?(0x0,metric_logger_1[a4_0x2174('0x0')])(_0x2cbc04['axiosException'][a4_0x2174('0x10')]):metric_logger_1[a4_0x2174('0x1b')]);throw _0x2cbc04;}});}[a4_0x2174('0xf')](_0x324597){var _0x407184;return __awaiter(this,void 0x0,void 0x0,function*(){if(environment_1[a4_0x2174('0x2')]){output[a4_0x2174('0x15')]({'title':a4_0x2174('0x7'),'bodyLines':[a4_0x2174('0x8')+this[a4_0x2174('0x19')],a4_0x2174('0x12')+_0x324597]});}const _0x11433c=(0x0,metric_logger_1['createMetricRecorder'])('completeRunGroup');try{const _0x35b392=yield(0x0,axios_1['axiosMultipleTries'])(()=>this[a4_0x2174('0x13')][a4_0x2174('0x16')]('/nx-cloud/executions/complete-run-group',{'runGroup':this[a4_0x2174('0x19')],'agentName':this['agentName'],'criticalErrorMessage':_0x324597}));if(environment_1[a4_0x2174('0x2')]){output[a4_0x2174('0x15')]({'title':a4_0x2174('0x1c')});}_0x11433c[a4_0x2174('0x3')]((0x0,metric_logger_1[a4_0x2174('0x0')])(_0x35b392));}catch(_0x4b52cd){_0x11433c['recordMetric'](((_0x407184=_0x4b52cd===null||_0x4b52cd===void 0x0?void 0x0:_0x4b52cd[a4_0x2174('0xd')])===null||_0x407184===void 0x0?void 0x0:_0x407184['response'])?(0x0,metric_logger_1[a4_0x2174('0x0')])(_0x4b52cd[a4_0x2174('0xd')][a4_0x2174('0x10')]):metric_logger_1[a4_0x2174('0x1b')]);console[a4_0x2174('0xe')](_0x4b52cd);}});}}exports[a4_0x2174('0x11')]=DistributedAgentApi; | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DistributedAgentApi = void 0; | ||
const axios_1 = require("../../../utilities/axios"); | ||
const environment_1 = require("../../../utilities/environment"); | ||
const metric_logger_1 = require("../../../utilities/metric-logger"); | ||
const { output } = require('../../../utilities/nx-imports'); | ||
class DistributedAgentApi { | ||
constructor(options, runGroup, agentName) { | ||
this.runGroup = runGroup; | ||
this.agentName = agentName; | ||
this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options); | ||
} | ||
tasks(executionId, statusCode, completedTasks) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const recorder = (0, metric_logger_1.createMetricRecorder)('dtePollTasks'); | ||
try { | ||
const res = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/tasks', { | ||
runGroup: this.runGroup, | ||
agentName: this.agentName, | ||
executionId, | ||
statusCode, | ||
completedTasks, | ||
})); | ||
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(res)); | ||
return res.data; | ||
} | ||
catch (e) { | ||
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response) | ||
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response) | ||
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY); | ||
throw e; | ||
} | ||
}); | ||
} | ||
completeRunGroupWithError(error) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (environment_1.VERBOSE_LOGGING) { | ||
output.note({ | ||
title: 'Completing run group with an error', | ||
bodyLines: [`runGroup: ${this.runGroup}`, `error: ${error}`], | ||
}); | ||
} | ||
const recorder = (0, metric_logger_1.createMetricRecorder)('completeRunGroup'); | ||
try { | ||
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/complete-run-group', { | ||
runGroup: this.runGroup, | ||
agentName: this.agentName, | ||
criticalErrorMessage: error, | ||
})); | ||
if (environment_1.VERBOSE_LOGGING) { | ||
output.note({ | ||
title: 'Completed run group with an error', | ||
}); | ||
} | ||
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp)); | ||
} | ||
catch (e) { | ||
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response) | ||
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response) | ||
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY); | ||
console.error(e); | ||
} | ||
}); | ||
} | ||
} | ||
exports.DistributedAgentApi = DistributedAgentApi; | ||
//# sourceMappingURL=distributed-agent.api.js.map |
@@ -1,1 +0,239 @@ | ||
const a5_0x1751=['Agent\x20','toString','cacheDirectory','startAgent','.lock','readdirSync','next','Waiting...','Waiter','child_process','VERBOSE_LOGGING','\x20--projects=','__awaiter','Error:','target','nx.json','random','../../../utilities/environment','Fetching\x20tasks...','default','getRunGroup','NX_AGENT_NAME','wait','maxParallel','inherit','If\x20you\x20believe\x20this\x20is\x20the\x20case,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22.','warn','defineProperty','readFileSync','unlinkSync','value','projectName','maxParallel:\x20','getTime','DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE','throw','configuration','length','../../../utilities/create-no-new-messages-timeout','CIRCLECI','retryDuring:\x20','taskId','We\x20have\x20detected\x20other\x20agents\x20running\x20in\x20this\x20workspace.\x20This\x20can\x20cause\x20unexpected\x20behavior.','../../../utilities/nx-imports','writeFileSync','Other\x20Nx\x20Cloud\x20Agents\x20Detected','completeRunGroupWithError','submitRunMetrics','CIRCLE_STAGE','./distributed-agent.api','Critical\x20Error\x20in\x20Agent:\x20\x22','printRunGroupError','\x20--parallel\x20--max-parallel=','Duplicate\x20Agent\x20ID\x20Detected','../../error/print-run-group-error','API\x20Response','completed','error','DistributedAgentApi','includes','../../../utilities/waiter','Starting\x20an\x20agent\x20for\x20running\x20Nx\x20tasks','completedTasks','npx\x20nx\x20run-many\x20--target=','note','retryDuring','tasks','../../../utilities/metric-logger','This\x20can\x20also\x20be\x20a\x20false\x20positive\x20caused\x20by\x20agents\x20that\x20did\x20not\x20shut\x20down\x20correctly.','criticalErrorMessage','exit','Executing:\x20\x27','executionId','join','assign','params','push','env','apply','then','End\x20all\x20currently\x20running\x20agents,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22,\x20and\x20try\x20again.','__esModule','existsSync','floor','strip-json-comments','parse','tasksRunnerOptions','/tasks-hashes-','projects','SIGINT','options',').\x20Tasks\x20hashes\x20haven\x27t\x20been\x20recorded.','./node_modules/.cache/nx'];(function(_0x2829eb,_0x175180){const _0xf68bcc=function(_0x37aef8){while(--_0x37aef8){_0x2829eb['push'](_0x2829eb['shift']());}};_0xf68bcc(++_0x175180);}(a5_0x1751,0x10c));const a5_0xf68b=function(_0x2829eb,_0x175180){_0x2829eb=_0x2829eb-0x0;let _0xf68bcc=a5_0x1751[_0x2829eb];return _0xf68bcc;};'use strict';var __awaiter=this&&this[a5_0xf68b('0x17')]||function(_0x40fdcb,_0x4c5cd5,_0x5859c3,_0x35b582){function _0x49acf0(_0x4e4e50){return _0x4e4e50 instanceof _0x5859c3?_0x4e4e50:new _0x5859c3(function(_0x37a0f3){_0x37a0f3(_0x4e4e50);});}return new(_0x5859c3||(_0x5859c3=Promise))(function(_0x340b9f,_0x1cf0a7){function _0x2672e6(_0x1e2823){try{_0x53c3de(_0x35b582['next'](_0x1e2823));}catch(_0x18bbf6){_0x1cf0a7(_0x18bbf6);}}function _0x3f1ec2(_0x101953){try{_0x53c3de(_0x35b582[a5_0xf68b('0x2e')](_0x101953));}catch(_0xfb604d){_0x1cf0a7(_0xfb604d);}}function _0x53c3de(_0x11eb43){_0x11eb43['done']?_0x340b9f(_0x11eb43[a5_0xf68b('0x29')]):_0x49acf0(_0x11eb43[a5_0xf68b('0x29')])[a5_0xf68b('0x5a')](_0x2672e6,_0x3f1ec2);}_0x53c3de((_0x35b582=_0x35b582[a5_0xf68b('0x59')](_0x40fdcb,_0x4c5cd5||[]))[a5_0xf68b('0x11')]());});};Object[a5_0xf68b('0x26')](exports,a5_0xf68b('0x5c'),{'value':!![]});exports[a5_0xf68b('0xe')]=void 0x0;const child_process_1=require(a5_0xf68b('0x14'));const stripJsonComments=require(a5_0xf68b('0x2'));const distributed_agent_api_1=require(a5_0xf68b('0x3c'));const waiter_1=require(a5_0xf68b('0x47'));const environment_1=require(a5_0xf68b('0x1c'));const print_run_group_error_1=require(a5_0xf68b('0x41'));const create_no_new_messages_timeout_1=require(a5_0xf68b('0x31'));const fs_1=require('fs');const metric_logger_1=require(a5_0xf68b('0x4e'));const {output}=require(a5_0xf68b('0x36'));function executeTasks(_0x5aab92,_0x4f3a15){return __awaiter(this,void 0x0,void 0x0,function*(){let _0x2e284e=0x0;let _0x25cbbb=null;const _0x453e59=(0x0,create_no_new_messages_timeout_1['createNoNewMessagesTimeout'])();const _0x1557a0=new waiter_1[(a5_0xf68b('0x13'))]();let _0x37533f=[];const _0x25a2fe=new Date();let _0x54069e=![];while(!![]){if(environment_1['VERBOSE_LOGGING']){output[a5_0xf68b('0x4b')]({'title':a5_0xf68b('0x1d')});}_0x25cbbb=yield _0x4f3a15[a5_0xf68b('0x4d')](_0x25cbbb?_0x25cbbb[a5_0xf68b('0x53')]:null,_0x2e284e,_0x37533f);if(environment_1[a5_0xf68b('0x15')]){output[a5_0xf68b('0x4b')]({'title':a5_0xf68b('0x42'),'bodyLines':['completed:\x20'+_0x25cbbb['completed'],a5_0xf68b('0x33')+_0x25cbbb['retryDuring'],'executionId:\x20'+_0x25cbbb[a5_0xf68b('0x53')],'number\x20of\x20tasks:\x20'+_0x25cbbb[a5_0xf68b('0x4d')]['length'],'error:\x20'+_0x25cbbb['criticalErrorMessage'],a5_0xf68b('0x2b')+_0x25cbbb[a5_0xf68b('0x22')]]});}if(_0x25cbbb[a5_0xf68b('0x50')]){output[a5_0xf68b('0x44')]({'title':'Distributed\x20Execution\x20Terminated','bodyLines':[a5_0xf68b('0x18'),_0x25cbbb[a5_0xf68b('0x50')]]});process[a5_0xf68b('0x51')](0x0);}if((_0x25cbbb===null||_0x25cbbb===void 0x0?void 0x0:_0x25cbbb[a5_0xf68b('0x4c')])&&(_0x25cbbb===null||_0x25cbbb===void 0x0?void 0x0:_0x25cbbb[a5_0xf68b('0x4c')])!==0x0&&!_0x54069e&&new Date()[a5_0xf68b('0x2c')]()-_0x25a2fe[a5_0xf68b('0x2c')]()>_0x25cbbb[a5_0xf68b('0x4c')]){yield _0x1557a0['wait']();continue;}if(_0x25cbbb[a5_0xf68b('0x43')])return;_0x453e59(_0x25cbbb[a5_0xf68b('0x4d')]['map'](_0xe22d24=>_0xe22d24[a5_0xf68b('0x34')])[a5_0xf68b('0x54')](''));if(!_0x25cbbb[a5_0xf68b('0x53')]){if(environment_1[a5_0xf68b('0x15')]){output['note']({'title':a5_0xf68b('0x12')});}yield _0x1557a0[a5_0xf68b('0x21')]();_0x2e284e=0x0;_0x37533f=[];continue;}_0x1557a0['reset']();_0x54069e=!![];const _0x1c2551=invokeTasksUsingRunMany(_0x5aab92,_0x25cbbb['executionId'],_0x25cbbb[a5_0xf68b('0x4d')],_0x25cbbb[a5_0xf68b('0x22')]);_0x2e284e=_0x1c2551['completedStatusCode'];_0x37533f=_0x1c2551[a5_0xf68b('0x49')];}});}function readCompletedTasks(_0x13c5eb,_0x50a61b){const _0x57a2d2='Command\x20execution\x20failed\x20(distributed\x20task\x20execution:\x20'+_0x50a61b+a5_0xf68b('0x9');let _0x522c93;try{const _0x71163f=_0x13c5eb[a5_0xf68b('0xd')]||'./node_modules/.cache/nx';const _0x32d155=_0x71163f+a5_0xf68b('0x5')+_0x50a61b;_0x522c93=JSON[a5_0xf68b('0x3')]((0x0,fs_1[a5_0xf68b('0x27')])(_0x32d155)[a5_0xf68b('0xc')]());(0x0,fs_1[a5_0xf68b('0x28')])(_0x32d155);}catch(_0x44b236){throw new Error(_0x57a2d2);}if(_0x522c93[a5_0xf68b('0x30')]==0x0){throw new Error(_0x57a2d2);}return _0x522c93;}function invokeTasksUsingRunMany(_0x3bbd17,_0x4b9f87,_0x14c7dd,_0x98a585){let _0x3d0c0a=0x0;const _0x39489d=[];for(const _0x4e2b85 of groupByTarget(_0x14c7dd)){const _0x452315=_0x4e2b85['configuration']?'--configuration='+_0x4e2b85[a5_0xf68b('0x2f')]:'';const _0x1b6975=_0x98a585>0x1?a5_0xf68b('0x3f')+_0x98a585:'';const _0x1024ba=a5_0xf68b('0x4a')+_0x4e2b85[a5_0xf68b('0x19')]+'\x20'+_0x452315+a5_0xf68b('0x16')+_0x4e2b85[a5_0xf68b('0x6')]['join'](',')+'\x20'+_0x4e2b85[a5_0xf68b('0x56')]+_0x1b6975;if(environment_1[a5_0xf68b('0x15')]){output[a5_0xf68b('0x4b')]({'title':a5_0xf68b('0x52')+_0x1024ba+'\x27'});}try{(0x0,child_process_1['execSync'])(_0x1024ba,{'stdio':[a5_0xf68b('0x23'),'inherit',a5_0xf68b('0x23')],'env':Object[a5_0xf68b('0x55')](Object['assign']({},process['env']),{'NX_CACHE_FAILURES':'true','NX_CLOUD_DISTRIBUTED_EXECUTION_ID':_0x4b9f87})});}catch(_0x55c8c1){if(_0x55c8c1['status']===environment_1[a5_0xf68b('0x2d')]){throw _0x55c8c1;}else{_0x3d0c0a=0x1;}}finally{_0x39489d[a5_0xf68b('0x57')](...readCompletedTasks(_0x3bbd17,_0x4b9f87));}}return{'completedStatusCode':_0x3d0c0a,'completedTasks':_0x39489d};}function groupByTarget(_0x18c88e){const _0x4c17ec=[];_0x18c88e['forEach'](_0x514484=>{const _0x1d7c3d=_0x4c17ec['find'](_0x49e18b=>_0x49e18b[a5_0xf68b('0x19')]===_0x514484[a5_0xf68b('0x19')]&&_0x49e18b[a5_0xf68b('0x2f')]===_0x514484[a5_0xf68b('0x2f')]);if(_0x1d7c3d){_0x1d7c3d[a5_0xf68b('0x6')][a5_0xf68b('0x57')](_0x514484[a5_0xf68b('0x2a')]);}else{_0x4c17ec[a5_0xf68b('0x57')]({'target':_0x514484[a5_0xf68b('0x19')],'projects':[_0x514484['projectName']],'params':_0x514484['params'],'configuration':_0x514484[a5_0xf68b('0x2f')]});}});return _0x4c17ec;}function getAgentName(){if(process[a5_0xf68b('0x58')]['NX_AGENT_NAME']!==undefined){return process['env'][a5_0xf68b('0x20')];}else if(process[a5_0xf68b('0x58')][a5_0xf68b('0x32')]!==undefined){return process[a5_0xf68b('0x58')][a5_0xf68b('0x3b')];}else{return a5_0xf68b('0xb')+Math[a5_0xf68b('0x1')](Math[a5_0xf68b('0x1b')]()*0x186a0);}}function createAgentLockfile(_0xad0d39,_0x5d18a8){const _0x18443a=_0xad0d39[a5_0xf68b('0xd')]||a5_0xf68b('0xa');const _0x38565e=_0x18443a+'/lockfiles';const _0x2bfbf4=_0x38565e+'/'+_0x5d18a8+'.lock';if(!(0x0,fs_1[a5_0xf68b('0x0')])(_0x38565e)){(0x0,fs_1['mkdirSync'])(_0x38565e,{'recursive':!![]});}const _0x348f2f=(0x0,fs_1[a5_0xf68b('0x10')])(_0x38565e);if(_0x348f2f[a5_0xf68b('0x30')]){if(_0x348f2f[a5_0xf68b('0x46')](_0x5d18a8+a5_0xf68b('0xf'))){output[a5_0xf68b('0x44')]({'title':a5_0xf68b('0x40'),'bodyLines':['We\x20have\x20detected\x20another\x20agent\x20with\x20this\x20ID\x20running\x20in\x20this\x20workspace.\x20This\x20should\x20not\x20happen.','',a5_0xf68b('0x5b')]});process[a5_0xf68b('0x51')](0x1);}output[a5_0xf68b('0x25')]({'title':a5_0xf68b('0x38'),'bodyLines':[a5_0xf68b('0x35'),'',a5_0xf68b('0x4f'),a5_0xf68b('0x24')]});}(0x0,fs_1[a5_0xf68b('0x37')])(_0x2bfbf4,'');process['on'](a5_0xf68b('0x51'),()=>cleanupAgentLockfile(_0x2bfbf4));process['on'](a5_0xf68b('0x7'),()=>cleanupAgentLockfile(_0x2bfbf4));}function cleanupAgentLockfile(_0x2e6009){if((0x0,fs_1['existsSync'])(_0x2e6009)){(0x0,fs_1[a5_0xf68b('0x28')])(_0x2e6009);}}function startAgent(){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x47afe5=(0x0,environment_1[a5_0xf68b('0x1f')])();if(!_0x47afe5){(0x0,print_run_group_error_1[a5_0xf68b('0x3e')])();return process[a5_0xf68b('0x51')](0x1);}output[a5_0xf68b('0x4b')]({'title':a5_0xf68b('0x48')});const _0x52c934=JSON['parse'](stripJsonComments((0x0,fs_1[a5_0xf68b('0x27')])(a5_0xf68b('0x1a'))['toString']()))[a5_0xf68b('0x4')][a5_0xf68b('0x1e')][a5_0xf68b('0x8')];const _0x24bf87=getAgentName();createAgentLockfile(_0x52c934,_0x24bf87);const _0x35615e=new distributed_agent_api_1[(a5_0xf68b('0x45'))](_0x52c934,_0x47afe5,_0x24bf87);return executeTasks(_0x52c934,_0x35615e)[a5_0xf68b('0x5a')](_0x14182b=>__awaiter(this,void 0x0,void 0x0,function*(){yield(0x0,metric_logger_1[a5_0xf68b('0x3a')])(_0x52c934);return _0x14182b;}))['catch'](_0x1f976d=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x35615e[a5_0xf68b('0x39')](a5_0xf68b('0x3d')+_0x1f976d['message']+'\x22');throw _0x1f976d;}));});}exports[a5_0xf68b('0xe')]=startAgent; | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.startAgent = void 0; | ||
const child_process_1 = require("child_process"); | ||
const stripJsonComments = require("strip-json-comments"); | ||
const distributed_agent_api_1 = require("./distributed-agent.api"); | ||
const waiter_1 = require("../../../utilities/waiter"); | ||
const environment_1 = require("../../../utilities/environment"); | ||
const print_run_group_error_1 = require("../../error/print-run-group-error"); | ||
const create_no_new_messages_timeout_1 = require("../../../utilities/create-no-new-messages-timeout"); | ||
const fs_1 = require("fs"); | ||
const metric_logger_1 = require("../../../utilities/metric-logger"); | ||
const { output } = require('../../../utilities/nx-imports'); | ||
function executeTasks(options, api) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let completedStatusCode = 0; | ||
let apiResponse = null; | ||
const failIfSameTasksIn30Mins = (0, create_no_new_messages_timeout_1.createNoNewMessagesTimeout)(); | ||
const waiter = new waiter_1.Waiter(); | ||
let completedTasks = []; | ||
const startTime = new Date(); | ||
let executedAnyTasks = false; | ||
while (true) { | ||
if (environment_1.VERBOSE_LOGGING) { | ||
output.note({ | ||
title: 'Fetching tasks...', | ||
}); | ||
} | ||
apiResponse = yield api.tasks(apiResponse ? apiResponse.executionId : null, completedStatusCode, completedTasks); | ||
if (environment_1.VERBOSE_LOGGING) { | ||
output.note({ | ||
title: 'API Response', | ||
bodyLines: [ | ||
`completed: ${apiResponse.completed}`, | ||
`retryDuring: ${apiResponse.retryDuring}`, | ||
`executionId: ${apiResponse.executionId}`, | ||
`number of tasks: ${apiResponse.tasks.length}`, | ||
`error: ${apiResponse.criticalErrorMessage}`, | ||
`maxParallel: ${apiResponse.maxParallel}`, | ||
], | ||
}); | ||
} | ||
if (apiResponse.criticalErrorMessage) { | ||
output.error({ | ||
title: 'Distributed Execution Terminated', | ||
bodyLines: ['Error:', apiResponse.criticalErrorMessage], | ||
}); | ||
process.exit(0); | ||
} | ||
// run group is completed but it might be a rerun | ||
// we will try several times before going further and | ||
// completed the response | ||
// we only do it if we haven't executed any tasks | ||
if ((apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.retryDuring) && | ||
(apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.retryDuring) !== 0 && | ||
!executedAnyTasks && | ||
new Date().getTime() - startTime.getTime() > apiResponse.retryDuring) { | ||
yield waiter.wait(); | ||
continue; | ||
} | ||
if (apiResponse.completed) | ||
return; | ||
failIfSameTasksIn30Mins(apiResponse.tasks.map((t) => t.taskId).join('')); | ||
if (!apiResponse.executionId) { | ||
if (environment_1.VERBOSE_LOGGING) { | ||
output.note({ | ||
title: 'Waiting...', | ||
}); | ||
} | ||
yield waiter.wait(); | ||
completedStatusCode = 0; | ||
completedTasks = []; | ||
continue; | ||
} | ||
waiter.reset(); | ||
executedAnyTasks = true; | ||
const r = invokeTasksUsingRunMany(options, apiResponse.executionId, apiResponse.tasks, apiResponse.maxParallel); | ||
completedStatusCode = r.completedStatusCode; | ||
completedTasks = r.completedTasks; | ||
} | ||
}); | ||
} | ||
function readCompletedTasks(options, distributedExecutionId) { | ||
const errorMessage = `Command execution failed (distributed task execution: ${distributedExecutionId}). Tasks hashes haven\'t been recorded.`; | ||
let completedTasks; | ||
try { | ||
const cacheDirectory = options.cacheDirectory || './node_modules/.cache/nx'; | ||
const taskHashesFile = `${cacheDirectory}/tasks-hashes-${distributedExecutionId}`; | ||
completedTasks = JSON.parse((0, fs_1.readFileSync)(taskHashesFile).toString()); | ||
// remove it such that if the next command crashes we don't read an obsolete file | ||
(0, fs_1.unlinkSync)(taskHashesFile); | ||
} | ||
catch (e) { | ||
throw new Error(errorMessage); | ||
} | ||
if (completedTasks.length == 0) { | ||
throw new Error(errorMessage); | ||
} | ||
return completedTasks; | ||
} | ||
function invokeTasksUsingRunMany(options, executionId, tasks, maxParallel) { | ||
let completedStatusCode = 0; | ||
const completedTasks = []; | ||
for (const g of groupByTarget(tasks)) { | ||
const config = g.configuration ? `--configuration=${g.configuration}` : ``; | ||
const parallel = maxParallel > 1 ? ` --parallel --max-parallel=${maxParallel}` : ``; | ||
// TODO use pnpx or yarn when needed | ||
const command = `npx nx run-many --target=${g.target} ${config} --projects=${g.projects.join(',')} ${g.params}${parallel}`; | ||
if (environment_1.VERBOSE_LOGGING) { | ||
output.note({ | ||
title: `Executing: '${command}'`, | ||
}); | ||
} | ||
try { | ||
(0, child_process_1.execSync)(command, { | ||
stdio: ['inherit', 'inherit', 'inherit'], | ||
env: Object.assign(Object.assign({}, process.env), { NX_CACHE_FAILURES: 'true', NX_CLOUD_DISTRIBUTED_EXECUTION_ID: executionId }), | ||
}); | ||
} | ||
catch (e) { | ||
if (e.status === environment_1.DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE) { | ||
throw e; | ||
} | ||
else { | ||
completedStatusCode = 1; | ||
} | ||
} | ||
finally { | ||
completedTasks.push(...readCompletedTasks(options, executionId)); | ||
} | ||
} | ||
return { completedStatusCode, completedTasks }; | ||
} | ||
function groupByTarget(tasks) { | ||
const res = []; | ||
tasks.forEach((t) => { | ||
const r = res.find((rr) => rr.target === t.target && rr.configuration === t.configuration); | ||
if (r) { | ||
r.projects.push(t.projectName); | ||
} | ||
else { | ||
res.push({ | ||
target: t.target, | ||
projects: [t.projectName], | ||
params: t.params, | ||
configuration: t.configuration, | ||
}); | ||
} | ||
}); | ||
return res; | ||
} | ||
function getAgentName() { | ||
if (process.env.NX_AGENT_NAME !== undefined) { | ||
return process.env.NX_AGENT_NAME; | ||
} | ||
else if (process.env.CIRCLECI !== undefined) { | ||
return process.env.CIRCLE_STAGE; | ||
} | ||
else { | ||
return `Agent ${Math.floor(Math.random() * 100000)}`; | ||
} | ||
} | ||
function createAgentLockfile(options, agentName) { | ||
const cacheDirectory = options.cacheDirectory || './node_modules/.cache/nx'; | ||
const lockFileDirectory = `${cacheDirectory}/lockfiles`; | ||
const lockFilePath = `${lockFileDirectory}/${agentName}.lock`; | ||
if (!(0, fs_1.existsSync)(lockFileDirectory)) { | ||
(0, fs_1.mkdirSync)(lockFileDirectory, { recursive: true }); | ||
} | ||
// Check for other agents' lockfiles and warn if exist | ||
const lockFiles = (0, fs_1.readdirSync)(lockFileDirectory); | ||
if (lockFiles.length) { | ||
// Check to make sure the current agent name is not in use (only 1/100000 ^ 2 chance of this) | ||
if (lockFiles.includes(`${agentName}.lock`)) { | ||
output.error({ | ||
title: 'Duplicate Agent ID Detected', | ||
bodyLines: [ | ||
'We have detected another agent with this ID running in this workspace. This should not happen.', | ||
'', | ||
'End all currently running agents, run "npx nx-cloud clean-up-agents", and try again.', | ||
], | ||
}); | ||
process.exit(1); | ||
} | ||
output.warn({ | ||
title: 'Other Nx Cloud Agents Detected', | ||
bodyLines: [ | ||
'We have detected other agents running in this workspace. This can cause unexpected behavior.', | ||
'', | ||
'This can also be a false positive caused by agents that did not shut down correctly.', | ||
'If you believe this is the case, run "npx nx-cloud clean-up-agents".', | ||
], | ||
}); | ||
} | ||
(0, fs_1.writeFileSync)(lockFilePath, ''); | ||
process.on('exit', () => cleanupAgentLockfile(lockFilePath)); | ||
process.on('SIGINT', () => cleanupAgentLockfile(lockFilePath)); | ||
} | ||
function cleanupAgentLockfile(lockFilePath) { | ||
if ((0, fs_1.existsSync)(lockFilePath)) { | ||
(0, fs_1.unlinkSync)(lockFilePath); | ||
} | ||
} | ||
function startAgent() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const runGroup = (0, environment_1.getRunGroup)(); | ||
if (!runGroup) { | ||
(0, print_run_group_error_1.printRunGroupError)(); | ||
return process.exit(1); | ||
} | ||
output.note({ | ||
title: 'Starting an agent for running Nx tasks', | ||
}); | ||
const options = JSON.parse(stripJsonComments((0, fs_1.readFileSync)('nx.json').toString())).tasksRunnerOptions.default.options; | ||
const agentName = getAgentName(); | ||
createAgentLockfile(options, agentName); | ||
const api = new distributed_agent_api_1.DistributedAgentApi(options, runGroup, agentName); | ||
return executeTasks(options, api) | ||
.then((res) => __awaiter(this, void 0, void 0, function* () { | ||
yield (0, metric_logger_1.submitRunMetrics)(options); | ||
return res; | ||
})) | ||
.catch((e) => __awaiter(this, void 0, void 0, function* () { | ||
yield api.completeRunGroupWithError(`Critical Error in Agent: "${e.message}"`); | ||
throw e; | ||
})); | ||
}); | ||
} | ||
exports.startAgent = startAgent; | ||
//# sourceMappingURL=distributed-agent.impl.js.map |
@@ -1,1 +0,130 @@ | ||
const a6_0xfc87=['../../../utilities/environment','response','/nx-cloud/executions/complete-run-group','createStartRequest','dteStatus','next','../../../utilities/axios','project','NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT','__awaiter','done','DistributedExecutionApi','maxParallel','defineProperty','mapRespToPerfEntry','exit','__esModule','createMetricRecorder','axiosException','post','error','RUNNER_FAILURE_PERF_ENTRY','hash','throw','../../../utilities/nx-imports','../../../utilities/metric-logger','start','recordMetric','agentCount','configuration','overrides','axiosMultipleTries','stopAgentsOnFailure','/nx-cloud/executions/status','message','false','join','target','data','value','completeRunGroupWithError','map','NX_CLOUD_DISTRIBUTED_EXECUTION_STOP_AGENTS_ON_FAILURE','Workspace\x20is\x20disabled.\x20Cannot\x20perform\x20distributed\x20task\x20executions.','then','enabled','dteStart','apply','parallel','completeRunGroup','parseCommand','apiAxiosInstance'];(function(_0x453ea5,_0xfc874c){const _0x6d32af=function(_0x4f7ac0){while(--_0x4f7ac0){_0x453ea5['push'](_0x453ea5['shift']());}};_0x6d32af(++_0xfc874c);}(a6_0xfc87,0x187));const a6_0x6d32=function(_0x453ea5,_0xfc874c){_0x453ea5=_0x453ea5-0x0;let _0x6d32af=a6_0xfc87[_0x453ea5];return _0x6d32af;};'use strict';var __awaiter=this&&this[a6_0x6d32('0x22')]||function(_0x173335,_0x3740f4,_0x1ffdab,_0x568328){function _0x131ee9(_0x4d5712){return _0x4d5712 instanceof _0x1ffdab?_0x4d5712:new _0x1ffdab(function(_0x4f6bf7){_0x4f6bf7(_0x4d5712);});}return new(_0x1ffdab||(_0x1ffdab=Promise))(function(_0x5ace61,_0x1d9f59){function _0x4f4b3a(_0x3d47c0){try{_0x3debff(_0x568328[a6_0x6d32('0x1e')](_0x3d47c0));}catch(_0x38f719){_0x1d9f59(_0x38f719);}}function _0x820cfe(_0x1b9b07){try{_0x3debff(_0x568328[a6_0x6d32('0x30')](_0x1b9b07));}catch(_0xd6d69f){_0x1d9f59(_0xd6d69f);}}function _0x3debff(_0x3eb92c){_0x3eb92c[a6_0x6d32('0x23')]?_0x5ace61(_0x3eb92c[a6_0x6d32('0xc')]):_0x131ee9(_0x3eb92c[a6_0x6d32('0xc')])[a6_0x6d32('0x11')](_0x4f4b3a,_0x820cfe);}_0x3debff((_0x568328=_0x568328[a6_0x6d32('0x14')](_0x173335,_0x3740f4||[]))[a6_0x6d32('0x1e')]());});};Object[a6_0x6d32('0x26')](exports,a6_0x6d32('0x29'),{'value':!![]});exports[a6_0x6d32('0x1c')]=exports[a6_0x6d32('0x24')]=void 0x0;const axios_1=require(a6_0x6d32('0x1f'));const environment_1=require(a6_0x6d32('0x19'));const metric_logger_1=require(a6_0x6d32('0x32'));const {output,unparse}=require(a6_0x6d32('0x31'));class DistributedExecutionApi{constructor(_0x4cdac9){this[a6_0x6d32('0x18')]=(0x0,axios_1['createApiAxiosInstance'])(_0x4cdac9);}[a6_0x6d32('0x33')](_0x4a1ecb){var _0x5b0abb;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x41f8fa=(0x0,metric_logger_1[a6_0x6d32('0x2a')])(a6_0x6d32('0x13'));let _0x2743f2;try{_0x2743f2=yield(0x0,axios_1['axiosMultipleTries'])(()=>this[a6_0x6d32('0x18')][a6_0x6d32('0x2c')]('/nx-cloud/executions/start',_0x4a1ecb));_0x41f8fa[a6_0x6d32('0x0')]((0x0,metric_logger_1[a6_0x6d32('0x27')])(_0x2743f2));}catch(_0x2a92d8){_0x41f8fa[a6_0x6d32('0x0')](((_0x5b0abb=_0x2a92d8===null||_0x2a92d8===void 0x0?void 0x0:_0x2a92d8['axiosException'])===null||_0x5b0abb===void 0x0?void 0x0:_0x5b0abb[a6_0x6d32('0x1a')])?(0x0,metric_logger_1['mapRespToPerfEntry'])(_0x2a92d8[a6_0x6d32('0x2b')][a6_0x6d32('0x1a')]):metric_logger_1[a6_0x6d32('0x2e')]);throw _0x2a92d8;}if(!_0x2743f2['data'][a6_0x6d32('0x12')]){throw new Error(a6_0x6d32('0x10'));}if(_0x2743f2[a6_0x6d32('0xb')][a6_0x6d32('0x2d')]){throw new Error(_0x2743f2[a6_0x6d32('0xb')][a6_0x6d32('0x2d')]);}return _0x2743f2[a6_0x6d32('0xb')]['id'];});}['status'](_0xf8edd6){var _0x166268;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x30ae36=(0x0,metric_logger_1[a6_0x6d32('0x2a')])(a6_0x6d32('0x1d'));try{const _0x3472e3=yield(0x0,axios_1[a6_0x6d32('0x4')])(()=>this[a6_0x6d32('0x18')][a6_0x6d32('0x2c')](a6_0x6d32('0x6'),{'id':_0xf8edd6}));_0x30ae36[a6_0x6d32('0x0')]((0x0,metric_logger_1[a6_0x6d32('0x27')])(_0x3472e3));return _0x3472e3['data'];}catch(_0xf36c07){_0x30ae36[a6_0x6d32('0x0')](((_0x166268=_0xf36c07===null||_0xf36c07===void 0x0?void 0x0:_0xf36c07['axiosException'])===null||_0x166268===void 0x0?void 0x0:_0x166268[a6_0x6d32('0x1a')])?(0x0,metric_logger_1[a6_0x6d32('0x27')])(_0xf36c07[a6_0x6d32('0x2b')]['response']):metric_logger_1[a6_0x6d32('0x2e')]);output[a6_0x6d32('0x2d')]({'title':_0xf36c07[a6_0x6d32('0x7')]});process[a6_0x6d32('0x28')](0x1);}});}[a6_0x6d32('0xd')](_0x89aca7,_0x55b619){var _0x30a27d;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x3171f0=(0x0,metric_logger_1[a6_0x6d32('0x2a')])(a6_0x6d32('0x16'));try{const _0x7c7023=yield(0x0,axios_1[a6_0x6d32('0x4')])(()=>this[a6_0x6d32('0x18')][a6_0x6d32('0x2c')](a6_0x6d32('0x1b'),{'runGroup':_0x89aca7,'criticalErrorMessage':_0x55b619}),0x3);_0x3171f0[a6_0x6d32('0x0')]((0x0,metric_logger_1[a6_0x6d32('0x27')])(_0x7c7023));}catch(_0x4f2cd9){_0x3171f0[a6_0x6d32('0x0')](((_0x30a27d=_0x4f2cd9===null||_0x4f2cd9===void 0x0?void 0x0:_0x4f2cd9[a6_0x6d32('0x2b')])===null||_0x30a27d===void 0x0?void 0x0:_0x30a27d[a6_0x6d32('0x1a')])?(0x0,metric_logger_1[a6_0x6d32('0x27')])(_0x4f2cd9[a6_0x6d32('0x2b')][a6_0x6d32('0x1a')]):metric_logger_1[a6_0x6d32('0x2e')]);}});}}exports['DistributedExecutionApi']=DistributedExecutionApi;function createStartRequest(_0x22042e,_0x7ec69c,_0x401284){const _0x2887f8=_0x7ec69c['map'](_0x16dda5=>{return _0x16dda5[a6_0x6d32('0xe')](_0x3dfa92=>{return{'taskId':_0x3dfa92['id'],'hash':_0x3dfa92[a6_0x6d32('0x2f')],'projectName':_0x3dfa92[a6_0x6d32('0xa')][a6_0x6d32('0x20')],'target':_0x3dfa92[a6_0x6d32('0xa')][a6_0x6d32('0xa')],'configuration':_0x3dfa92[a6_0x6d32('0xa')][a6_0x6d32('0x2')]||null,'params':unparse(_0x3dfa92[a6_0x6d32('0x3')])[a6_0x6d32('0x9')]('\x20')};});});const _0x5eb35a={'command':(0x0,environment_1[a6_0x6d32('0x17')])(),'branch':(0x0,environment_1['getBranch'])(),'runGroup':_0x22042e,'tasks':_0x2887f8,'maxParallel':calculateMaxParallel(_0x401284)};if(environment_1[a6_0x6d32('0x21')]){_0x5eb35a[a6_0x6d32('0x1')]=environment_1[a6_0x6d32('0x21')];}if(!environment_1[a6_0x6d32('0xf')]){_0x5eb35a[a6_0x6d32('0x5')]=![];}return _0x5eb35a;}exports[a6_0x6d32('0x1c')]=createStartRequest;function calculateMaxParallel(_0x4aab40){if(_0x4aab40[a6_0x6d32('0x15')]===a6_0x6d32('0x8')||_0x4aab40[a6_0x6d32('0x15')]===![]){return 0x1;}else if(_0x4aab40['parallel']==='true'||_0x4aab40[a6_0x6d32('0x15')]===!![]){return Number(_0x4aab40[a6_0x6d32('0x25')]||0x3);}else if(_0x4aab40[a6_0x6d32('0x15')]===undefined){return _0x4aab40[a6_0x6d32('0x25')]?Number(_0x4aab40[a6_0x6d32('0x25')]):0x3;}else{return Number(_0x4aab40[a6_0x6d32('0x15')])||0x3;}} | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createStartRequest = exports.DistributedExecutionApi = void 0; | ||
const axios_1 = require("../../../utilities/axios"); | ||
const environment_1 = require("../../../utilities/environment"); | ||
const metric_logger_1 = require("../../../utilities/metric-logger"); | ||
const { output, unparse } = require('../../../utilities/nx-imports'); | ||
class DistributedExecutionApi { | ||
constructor(options) { | ||
this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options); | ||
} | ||
start(params) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const recorder = (0, metric_logger_1.createMetricRecorder)('dteStart'); | ||
let resp; | ||
try { | ||
resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/start', params)); | ||
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp)); | ||
} | ||
catch (e) { | ||
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response) | ||
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response) | ||
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY); | ||
throw e; | ||
} | ||
if (!resp.data.enabled) { | ||
throw new Error(`Workspace is disabled. Cannot perform distributed task executions.`); | ||
} | ||
if (resp.data.error) { | ||
throw new Error(resp.data.error); | ||
} | ||
return resp.data.id; | ||
}); | ||
} | ||
status(id) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const recorder = (0, metric_logger_1.createMetricRecorder)('dteStatus'); | ||
try { | ||
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/status', { | ||
id, | ||
})); | ||
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp)); | ||
return resp.data; | ||
} | ||
catch (e) { | ||
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response) | ||
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response) | ||
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY); | ||
output.error({ | ||
title: e.message, | ||
}); | ||
process.exit(1); | ||
} | ||
}); | ||
} | ||
completeRunGroupWithError(runGroup, error) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const recorder = (0, metric_logger_1.createMetricRecorder)('completeRunGroup'); | ||
try { | ||
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/complete-run-group', { | ||
runGroup: runGroup, | ||
criticalErrorMessage: error, | ||
}), 3); | ||
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp)); | ||
} | ||
catch (e) { | ||
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response) | ||
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response) | ||
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY); | ||
} | ||
}); | ||
} | ||
} | ||
exports.DistributedExecutionApi = DistributedExecutionApi; | ||
function createStartRequest(runGroup, task, options) { | ||
const tasksToExecute = task.map((arr) => { | ||
return arr.map((t) => { | ||
return { | ||
taskId: t.id, | ||
hash: t.hash, | ||
projectName: t.target.project, | ||
target: t.target.target, | ||
configuration: t.target.configuration || null, | ||
params: unparse(t.overrides).join(' '), | ||
}; | ||
}); | ||
}); | ||
const request = { | ||
command: (0, environment_1.parseCommand)(), | ||
branch: (0, environment_1.getBranch)(), | ||
runGroup, | ||
tasks: tasksToExecute, | ||
maxParallel: calculateMaxParallel(options), | ||
}; | ||
if (environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT) { | ||
request.agentCount = environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT; | ||
} | ||
if (!environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_STOP_AGENTS_ON_FAILURE) { | ||
request.stopAgentsOnFailure = false; | ||
} | ||
return request; | ||
} | ||
exports.createStartRequest = createStartRequest; | ||
function calculateMaxParallel(options) { | ||
if (options.parallel === 'false' || options.parallel === false) { | ||
return 1; | ||
} | ||
else if (options.parallel === 'true' || options.parallel === true) { | ||
return Number(options.maxParallel || 3); | ||
} | ||
else if (options.parallel === undefined) { | ||
return options.maxParallel ? Number(options.maxParallel) : 3; | ||
} | ||
else { | ||
return Number(options.parallel) || 3; | ||
} | ||
} | ||
//# sourceMappingURL=distributed-execution.api.js.map |
@@ -1,1 +0,306 @@ | ||
const a7_0x34e6=['commandStatus','readFileSync','delete','../../../utilities/environment','start','strip-json-comments','Successfully\x20completed\x20running\x20the\x20command.','error','__awaiter','./distributed-execution.api','../../../utilities/nx-imports','length','projectGraph','COMPLETED','VERBOSE_LOGGING','error:\x20','startTask','exit','criticalErrorMessage','runUrl','executionStatus','targetDependencies','projects','toString','encryptionKey','has','rxjs/internal/Observable','../../../utilities/waiter','createStartRequest','url','retrieve','success','keys','FileStorage','../../../utilities/create-no-new-messages-timeout','filter','findTask','addVerticalSeparator','ENCRYPTION_KEY','submitRunMetrics','printRunGroupError','createTaskGraph','run','reset','join','stdout','dependencies','TaskGraphCreator','finally','completeRunGroupWithError','../../error/print-run-group-error','indexOf','Waiting...','cacheDirectory','note','Status\x20update','createNoNewMessagesTimeout','../../../utilities/metric-logger','addTaskToGraph','executionId:\x20','nodes','done','axiosException','E2EEncryption','number\x20of\x20completed\x20tasks:\x20','../../file-storage/file-storage','tasks','add','Retrieving\x20artifacts\x20from\x20','copyFilesFromCache','nxCloudDistributedTasksRunner','defineProperty','find','map','overrides','taskId','terminalOutput','nx.json','./node_modules/.cache/nx','log','Waiter','endTask','lifeCycle','Processing\x20task\x20','addTaskDependencies','wait','project','size','message','strictlyOrderedTargets','Found\x20unknown\x20task:\x20','defaultTargetDependencies','Unable\x20to\x20complete\x20a\x20run.','completedTasks','roots','write','hash','addDependencies','scheduleTask','self','target','next','assign','catch','parse','push','../../file-storage/e2e-encryption','See\x20run\x20details\x20at\x20','executionStatus:\x20','DistributedExecutionApi','Main\x20job\x20terminated\x20with\x20an\x20error:\x20\x22','then'];(function(_0x24362c,_0x34e6d7){const _0x842e8a=function(_0x22c559){while(--_0x22c559){_0x24362c['push'](_0x24362c['shift']());}};_0x842e8a(++_0x34e6d7);}(a7_0x34e6,0x6d));const a7_0x842e=function(_0x24362c,_0x34e6d7){_0x24362c=_0x24362c-0x0;let _0x842e8a=a7_0x34e6[_0x24362c];return _0x842e8a;};'use strict';var __awaiter=this&&this[a7_0x842e('0xb')]||function(_0x58ad7c,_0x682b83,_0x1e954e,_0xc87430){function _0x57941b(_0x325d79){return _0x325d79 instanceof _0x1e954e?_0x325d79:new _0x1e954e(function(_0x4c3298){_0x4c3298(_0x325d79);});}return new(_0x1e954e||(_0x1e954e=Promise))(function(_0x4e55ae,_0x5ea4b3){function _0x105cb2(_0x1b3856){try{_0x20544e(_0xc87430[a7_0x842e('0x68')](_0x1b3856));}catch(_0x57fa92){_0x5ea4b3(_0x57fa92);}}function _0x52b6e4(_0x4b48a2){try{_0x20544e(_0xc87430['throw'](_0x4b48a2));}catch(_0x4269fb){_0x5ea4b3(_0x4269fb);}}function _0x20544e(_0xd8f49a){_0xd8f49a[a7_0x842e('0x40')]?_0x4e55ae(_0xd8f49a['value']):_0x57941b(_0xd8f49a['value'])[a7_0x842e('0x2')](_0x105cb2,_0x52b6e4);}_0x20544e((_0xc87430=_0xc87430['apply'](_0x58ad7c,_0x682b83||[]))[a7_0x842e('0x68')]());});};Object[a7_0x842e('0x4a')](exports,'__esModule',{'value':!![]});exports[a7_0x842e('0x32')]=exports[a7_0x842e('0x49')]=void 0x0;const Observable_1=require(a7_0x842e('0x1d'));const stripJsonComments=require(a7_0x842e('0x8'));const fs_1=require('fs');const distributed_execution_api_1=require(a7_0x842e('0xc'));const file_storage_1=require(a7_0x842e('0x44'));const e2e_encryption_1=require(a7_0x842e('0x6d'));const waiter_1=require(a7_0x842e('0x1e'));const environment_1=require(a7_0x842e('0x6'));const print_run_group_error_1=require(a7_0x842e('0x35'));const create_no_new_messages_timeout_1=require(a7_0x842e('0x25'));const metric_logger_1=require(a7_0x842e('0x3c'));const {output,getDependencyConfigs,getOutputs,unparse,Cache}=require(a7_0x842e('0xd'));class NoopLifeCycle{[a7_0x842e('0x65')](_0x30080d){}[a7_0x842e('0x13')](_0x21e332){}[a7_0x842e('0x54')](_0x290924,_0x4a4997){}}function runDistributedExecution(_0x2aedf8,_0x562812,_0x1777e8,_0x2c3b6c,_0x26ecbc,_0x4c630b,_0x50cb17){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x15fab5=JSON[a7_0x842e('0x6b')](stripJsonComments((0x0,fs_1[a7_0x842e('0x4')])(a7_0x842e('0x50'))[a7_0x842e('0x1a')]()));const _0x43c880=new TaskOrderer(_0x1777e8[a7_0x842e('0xf')],getDefaultDependencyConfigs(_0x15fab5,_0x562812))['splitTasksIntoStages'](_0x50cb17);const _0x4ed2dc=yield _0x2aedf8[a7_0x842e('0x7')]((0x0,distributed_execution_api_1[a7_0x842e('0x1f')])(_0x4c630b,_0x43c880,_0x562812));return yield processTasks(_0x2aedf8,_0x2c3b6c,_0x26ecbc,_0x562812,_0x4ed2dc,_0x50cb17,_0x1777e8);});}function processTasks(_0x69dedc,_0xb1e6e,_0x2a35b9,_0x4fdb2b,_0x2e9077,_0x487eaf,_0x12142f){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x32539b={};const _0x1633f7=(0x0,create_no_new_messages_timeout_1[a7_0x842e('0x3b')])();const _0x4b9a98=new waiter_1[(a7_0x842e('0x53'))]();while(!![]){if(environment_1[a7_0x842e('0x11')]){output[a7_0x842e('0x39')]({'title':a7_0x842e('0x37')});}yield _0x4b9a98[a7_0x842e('0x58')]();const _0x647103=yield _0x69dedc['status'](_0x2e9077);if(environment_1[a7_0x842e('0x11')]){output[a7_0x842e('0x39')]({'title':a7_0x842e('0x3a'),'bodyLines':[a7_0x842e('0x3e')+_0x2e9077,a7_0x842e('0x6f')+_0x647103[a7_0x842e('0x17')],a7_0x842e('0x43')+_0x647103[a7_0x842e('0x60')]['length'],a7_0x842e('0x12')+_0x647103[a7_0x842e('0x15')]]});}if(_0x647103[a7_0x842e('0x15')]){output['error']({'title':'Distributed\x20Execution\x20Terminated','bodyLines':['Error:',_0x647103[a7_0x842e('0x15')]]});process[a7_0x842e('0x14')](0x1);}_0x1633f7(_0x647103['completedTasks'][a7_0x842e('0xe')]);for(const _0x493799 of _0x647103[a7_0x842e('0x60')]){if(_0x32539b[_0x493799['taskId']])continue;yield processTask(_0xb1e6e,_0x2a35b9,_0x12142f,_0x4fdb2b,_0x487eaf,_0x493799);_0x4b9a98[a7_0x842e('0x2e')]();_0x32539b[_0x493799[a7_0x842e('0x4e')]]=!![];}if(_0x647103[a7_0x842e('0x17')]===a7_0x842e('0x10')){return{'commandStatus':_0x647103[a7_0x842e('0x3')],'runUrl':_0x647103[a7_0x842e('0x16')]};}}});}function processTask(_0x52d63a,_0x42f539,_0x3bc3fc,_0x4afdaa,_0x2a5d64,_0x6713ac){return __awaiter(this,void 0x0,void 0x0,function*(){if(environment_1['VERBOSE_LOGGING']){output[a7_0x842e('0x39')]({'title':a7_0x842e('0x56')+_0x6713ac[a7_0x842e('0x4e')]});}const _0x516ff6=_0x2a5d64[a7_0x842e('0x4b')](_0x44d436=>_0x6713ac['taskId']===_0x44d436['id']);if(!_0x516ff6){throw new Error(a7_0x842e('0x5d')+_0x6713ac['taskId']);}if(environment_1[a7_0x842e('0x11')]){output['note']({'title':a7_0x842e('0x47')+_0x6713ac[a7_0x842e('0x20')]});}yield _0x52d63a[a7_0x842e('0x21')](_0x6713ac[a7_0x842e('0x63')],_0x6713ac['url'],_0x4afdaa[a7_0x842e('0x38')]||a7_0x842e('0x51'));const _0x5df1d0=yield _0x42f539['get'](Object[a7_0x842e('0x69')](Object[a7_0x842e('0x69')]({},_0x516ff6),{'hash':_0x6713ac[a7_0x842e('0x63')]}));const _0x1f5ffe=getOutputs(_0x3bc3fc[a7_0x842e('0xf')][a7_0x842e('0x3f')],_0x516ff6);if(environment_1[a7_0x842e('0x11')]){output['note']({'title':'Extracting\x20artifacts','bodyLines':_0x1f5ffe});}yield _0x42f539[a7_0x842e('0x48')](_0x6713ac['hash'],_0x5df1d0,_0x1f5ffe);output['logCommand'](getCommand(_0x516ff6));process[a7_0x842e('0x30')][a7_0x842e('0x62')](_0x5df1d0[a7_0x842e('0x4f')]);output[a7_0x842e('0x28')]();});}function getCommand(_0x2698f6){const _0x596129=unparse(_0x2698f6[a7_0x842e('0x4d')]||{});const _0x173911=_0x2698f6[a7_0x842e('0x67')]['configuration']?':'+_0x2698f6[a7_0x842e('0x67')]['configuration']:'';return['nx',a7_0x842e('0x2d'),_0x2698f6[a7_0x842e('0x67')][a7_0x842e('0x59')]+':'+_0x2698f6[a7_0x842e('0x67')]['target']+_0x173911,..._0x596129][a7_0x842e('0x2f')]('\x20');}const nxCloudDistributedTasksRunner=(_0x532410,_0x2d3f1f,_0x5d4502)=>{if(environment_1[a7_0x842e('0x11')]){output[a7_0x842e('0x39')]({'title':'Starting\x20distributed\x20command\x20execution'});}_0x2d3f1f[a7_0x842e('0x55')]=new NoopLifeCycle();const _0xb7a129=(0x0,environment_1['getRunGroup'])();if(!_0xb7a129){(0x0,print_run_group_error_1[a7_0x842e('0x2b')])();return process[a7_0x842e('0x14')](0x1);}const _0x20c512=new e2e_encryption_1[(a7_0x842e('0x42'))](environment_1[a7_0x842e('0x29')]||_0x2d3f1f[a7_0x842e('0x1b')]);const _0x3f8a53=new file_storage_1[(a7_0x842e('0x24'))](_0x20c512);const _0x2d2ed6=new Cache(_0x2d3f1f);const _0x9550be=new distributed_execution_api_1[(a7_0x842e('0x0'))](_0x2d3f1f);runDistributedExecution(_0x9550be,_0x2d3f1f,_0x5d4502,_0x3f8a53,_0x2d2ed6,_0xb7a129,_0x532410)[a7_0x842e('0x2')](_0x15a21f=>__awaiter(void 0x0,void 0x0,void 0x0,function*(){if(_0x15a21f[a7_0x842e('0x3')]===0x0){output[a7_0x842e('0x22')]({'title':a7_0x842e('0x9'),'bodyLines':[a7_0x842e('0x6e')+_0x15a21f[a7_0x842e('0x16')]]});}else{output[a7_0x842e('0xa')]({'title':'Command\x20execution\x20failed.','bodyLines':[a7_0x842e('0x6e')+_0x15a21f[a7_0x842e('0x16')]]});}yield(0x0,metric_logger_1[a7_0x842e('0x2a')])(_0x2d3f1f);process[a7_0x842e('0x14')](_0x15a21f['commandStatus']);}))[a7_0x842e('0x6a')](_0x50962b=>{output[a7_0x842e('0xa')]({'title':a7_0x842e('0x5f'),'bodyLines':[_0x50962b[a7_0x842e('0x5b')]]});if(_0x50962b[a7_0x842e('0x41')]){console[a7_0x842e('0x52')](_0x50962b[a7_0x842e('0x41')]);}else{console[a7_0x842e('0x52')](_0x50962b);}_0x9550be[a7_0x842e('0x34')](_0xb7a129,a7_0x842e('0x1')+_0x50962b[a7_0x842e('0x5b')]+'\x22')[a7_0x842e('0x33')](()=>process[a7_0x842e('0x14')](0x1));});return new Observable_1['Observable'](()=>{});};exports[a7_0x842e('0x49')]=nxCloudDistributedTasksRunner;class TaskOrderer{constructor(_0x4c6cf4,_0x1106a3){this['projectGraph']=_0x4c6cf4;this[a7_0x842e('0x5e')]=_0x1106a3;}['splitTasksIntoStages'](_0x5ea7fd){if(_0x5ea7fd[a7_0x842e('0xe')]===0x0)return[];const _0x3fba03=[];const _0x152ba4=this[a7_0x842e('0x2c')](_0x5ea7fd);const _0x5aef4e=new Set(_0x5ea7fd[a7_0x842e('0x4c')](_0xa1dc2f=>_0xa1dc2f['id']));let _0x412686=0x0;while(_0x5aef4e[a7_0x842e('0x5a')]>0x0){const _0x3c734a=_0x3fba03[_0x412686]=[];for(const _0x30e6eb of _0x5aef4e){let _0x2b3ed0=!![];for(const _0x33c703 of _0x152ba4[a7_0x842e('0x31')][_0x30e6eb]){if(_0x5aef4e[a7_0x842e('0x1c')](_0x33c703)){_0x2b3ed0=![];break;}}if(!_0x2b3ed0){continue;}const _0x483830=_0x152ba4[a7_0x842e('0x45')][_0x30e6eb];_0x3c734a[a7_0x842e('0x6c')](_0x483830);}for(const _0xb81e90 of _0x3c734a){_0x5aef4e[a7_0x842e('0x5')](_0xb81e90['id']);}_0x412686++;}return _0x3fba03;}[a7_0x842e('0x2c')](_0x7cf852){const _0x1b2d18=new TaskGraphCreator(this[a7_0x842e('0xf')],this[a7_0x842e('0x5e')]);return _0x1b2d18['createTaskGraph'](_0x7cf852);}}class TaskGraphCreator{constructor(_0x4c9e7d,_0x3db06c){this[a7_0x842e('0xf')]=_0x4c9e7d;this[a7_0x842e('0x5e')]=_0x3db06c;}['createTaskGraph'](_0x48d83f){const _0x464349={'roots':[],'tasks':{},'dependencies':{}};for(const _0xf9ebfc of _0x48d83f){this[a7_0x842e('0x3d')](_0xf9ebfc,_0x464349);const _0x26ec83=getDependencyConfigs(_0xf9ebfc[a7_0x842e('0x67')],this[a7_0x842e('0x5e')],this[a7_0x842e('0xf')]);if(!_0x26ec83){continue;}this['addTaskDependencies'](_0xf9ebfc,_0x26ec83,_0x48d83f,_0x464349);}_0x464349[a7_0x842e('0x61')]=Object[a7_0x842e('0x23')](_0x464349['dependencies'])[a7_0x842e('0x26')](_0x1dc0e2=>_0x464349[a7_0x842e('0x31')][_0x1dc0e2]['length']===0x0);return _0x464349;}[a7_0x842e('0x57')](_0x146a35,_0x431801,_0x32853c,_0x552b0f){for(const _0x52d89f of _0x431801){if(_0x52d89f[a7_0x842e('0x19')]===a7_0x842e('0x66')){for(const _0x1ed670 of _0x32853c){if(_0x1ed670[a7_0x842e('0x67')][a7_0x842e('0x59')]===_0x146a35['target'][a7_0x842e('0x59')]&&_0x1ed670[a7_0x842e('0x67')][a7_0x842e('0x67')]===_0x52d89f['target']){_0x552b0f['dependencies'][_0x146a35['id']][a7_0x842e('0x6c')](_0x1ed670['id']);}}}else if(_0x52d89f[a7_0x842e('0x19')]===a7_0x842e('0x31')){const _0x2e3356=new Set();this[a7_0x842e('0x64')](_0x146a35[a7_0x842e('0x67')][a7_0x842e('0x59')],_0x52d89f[a7_0x842e('0x67')],_0x32853c,_0x552b0f,_0x146a35['id'],_0x2e3356);}}}[a7_0x842e('0x64')](_0x39864b,_0x127b05,_0x3a34e7,_0x1aaae5,_0x16e3fc,_0x52de8e){_0x52de8e[a7_0x842e('0x46')](_0x39864b);const _0x227ee8=this[a7_0x842e('0xf')][a7_0x842e('0x31')][_0x39864b];if(_0x227ee8){const _0xb51352=_0x227ee8[a7_0x842e('0x4c')](_0x56e114=>_0x56e114[a7_0x842e('0x67')]);for(const _0x505868 of _0xb51352){if(_0x52de8e[a7_0x842e('0x1c')](_0x505868)){continue;}const _0x3ad9dd=this[a7_0x842e('0x27')]({'project':_0x505868,'target':_0x127b05},_0x3a34e7);if(_0x3ad9dd){if(_0x1aaae5[a7_0x842e('0x31')][_0x16e3fc][a7_0x842e('0x36')](_0x3ad9dd['id'])===-0x1){_0x1aaae5[a7_0x842e('0x31')][_0x16e3fc][a7_0x842e('0x6c')](_0x3ad9dd['id']);}}else{this[a7_0x842e('0x64')](_0x505868,_0x127b05,_0x3a34e7,_0x1aaae5,_0x16e3fc,_0x52de8e);}}}}[a7_0x842e('0x27')]({project,target},_0x59c7d6){return _0x59c7d6[a7_0x842e('0x4b')](_0x2190fa=>_0x2190fa[a7_0x842e('0x67')]['project']===project&&_0x2190fa['target'][a7_0x842e('0x67')]===target);}[a7_0x842e('0x3d')](_0x1be5d3,_0x4f9e32){_0x4f9e32[a7_0x842e('0x45')][_0x1be5d3['id']]=_0x1be5d3;_0x4f9e32[a7_0x842e('0x31')][_0x1be5d3['id']]=[];}}exports[a7_0x842e('0x32')]=TaskGraphCreator;function getDefaultDependencyConfigs(_0x36c305,_0x305db9){var _0x57f9ce,_0x2755f1;const _0x882adb=(_0x57f9ce=_0x36c305[a7_0x842e('0x18')])!==null&&_0x57f9ce!==void 0x0?_0x57f9ce:{};const _0x353c95=_0x305db9?(_0x2755f1=_0x305db9[a7_0x842e('0x5c')])!==null&&_0x2755f1!==void 0x0?_0x2755f1:['build']:[];for(const _0x44f63b of _0x353c95){_0x882adb[_0x44f63b]=_0x882adb[_0x44f63b]||[];_0x882adb[_0x44f63b]['push']({'target':_0x44f63b,'projects':a7_0x842e('0x31')});}return _0x882adb;} | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TaskGraphCreator = exports.nxCloudDistributedTasksRunner = void 0; | ||
const Observable_1 = require("rxjs/internal/Observable"); | ||
const stripJsonComments = require("strip-json-comments"); | ||
const fs_1 = require("fs"); | ||
const distributed_execution_api_1 = require("./distributed-execution.api"); | ||
const file_storage_1 = require("../../file-storage/file-storage"); | ||
const e2e_encryption_1 = require("../../file-storage/e2e-encryption"); | ||
const waiter_1 = require("../../../utilities/waiter"); | ||
const environment_1 = require("../../../utilities/environment"); | ||
const print_run_group_error_1 = require("../../error/print-run-group-error"); | ||
const create_no_new_messages_timeout_1 = require("../../../utilities/create-no-new-messages-timeout"); | ||
const metric_logger_1 = require("../../../utilities/metric-logger"); | ||
const { output, getDependencyConfigs, getOutputs, unparse, Cache, } = require('../../../utilities/nx-imports'); | ||
class NoopLifeCycle { | ||
scheduleTask(task) { } | ||
startTask(task) { } | ||
endTask(task, code) { } | ||
} | ||
function runDistributedExecution(api, options, context, fileStorage, cache, runGroup, tasks) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const nxjson = JSON.parse(stripJsonComments((0, fs_1.readFileSync)('nx.json').toString())); | ||
const stages = new TaskOrderer(context.projectGraph, getDefaultDependencyConfigs(nxjson, options)).splitTasksIntoStages(tasks); | ||
const id = yield api.start((0, distributed_execution_api_1.createStartRequest)(runGroup, stages, options)); | ||
return yield processTasks(api, fileStorage, cache, options, id, tasks, context); | ||
}); | ||
} | ||
function processTasks(api, fileStorage, cache, options, executionId, tasks, context) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const processedTasks = {}; | ||
const failIfNumberOfCompletedTasksDoesNotChangeIn30Mins = (0, create_no_new_messages_timeout_1.createNoNewMessagesTimeout)(); | ||
const waiter = new waiter_1.Waiter(); | ||
while (true) { | ||
if (environment_1.VERBOSE_LOGGING) { | ||
output.note({ | ||
title: 'Waiting...', | ||
}); | ||
} | ||
yield waiter.wait(); | ||
const r = yield api.status(executionId); | ||
if (environment_1.VERBOSE_LOGGING) { | ||
output.note({ | ||
title: `Status update`, | ||
bodyLines: [ | ||
`executionId: ${executionId}`, | ||
`executionStatus: ${r.executionStatus}`, | ||
`number of completed tasks: ${r.completedTasks.length}`, | ||
`error: ${r.criticalErrorMessage}`, | ||
], | ||
}); | ||
} | ||
if (r.criticalErrorMessage) { | ||
output.error({ | ||
title: 'Distributed Execution Terminated', | ||
bodyLines: ['Error:', r.criticalErrorMessage], | ||
}); | ||
process.exit(1); | ||
} | ||
failIfNumberOfCompletedTasksDoesNotChangeIn30Mins(r.completedTasks.length); | ||
for (const t of r.completedTasks) { | ||
if (processedTasks[t.taskId]) | ||
continue; | ||
yield processTask(fileStorage, cache, context, options, tasks, t); | ||
waiter.reset(); | ||
processedTasks[t.taskId] = true; | ||
} | ||
if (r.executionStatus === 'COMPLETED') { | ||
return { commandStatus: r.commandStatus, runUrl: r.runUrl }; | ||
} | ||
} | ||
}); | ||
} | ||
function processTask(fileStorage, cache, context, options, tasks, completedTask) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (environment_1.VERBOSE_LOGGING) { | ||
output.note({ | ||
title: `Processing task ${completedTask.taskId}`, | ||
}); | ||
} | ||
const matchingTask = tasks.find((tt) => completedTask.taskId === tt.id); | ||
if (!matchingTask) { | ||
throw new Error(`Found unknown task: ${completedTask.taskId}`); | ||
} | ||
if (environment_1.VERBOSE_LOGGING) { | ||
output.note({ | ||
title: `Retrieving artifacts from ${completedTask.url}`, | ||
}); | ||
} | ||
yield fileStorage.retrieve(completedTask.hash, completedTask.url, options.cacheDirectory || './node_modules/.cache/nx'); | ||
const cachedResult = yield cache.get(Object.assign(Object.assign({}, matchingTask), { hash: completedTask.hash })); | ||
const outputs = getOutputs(context.projectGraph.nodes, matchingTask); | ||
if (environment_1.VERBOSE_LOGGING) { | ||
output.note({ | ||
title: `Extracting artifacts`, | ||
bodyLines: outputs, | ||
}); | ||
} | ||
yield cache.copyFilesFromCache(completedTask.hash, cachedResult, outputs); | ||
output.logCommand(getCommand(matchingTask)); | ||
process.stdout.write(cachedResult.terminalOutput); | ||
output.addVerticalSeparator(); | ||
}); | ||
} | ||
function getCommand(task) { | ||
const args = unparse(task.overrides || {}); | ||
const config = task.target.configuration | ||
? `:${task.target.configuration}` | ||
: ''; | ||
return [ | ||
'nx', | ||
'run', | ||
`${task.target.project}:${task.target.target}${config}`, | ||
...args, | ||
].join(' '); | ||
} | ||
const nxCloudDistributedTasksRunner = (tasks, options, context) => { | ||
if (environment_1.VERBOSE_LOGGING) { | ||
output.note({ | ||
title: 'Starting distributed command execution', | ||
}); | ||
} | ||
options.lifeCycle = new NoopLifeCycle(); | ||
const runGroup = (0, environment_1.getRunGroup)(); | ||
if (!runGroup) { | ||
(0, print_run_group_error_1.printRunGroupError)(); | ||
return process.exit(1); | ||
} | ||
const encryption = new e2e_encryption_1.E2EEncryption(environment_1.ENCRYPTION_KEY || options.encryptionKey); | ||
const fileStorage = new file_storage_1.FileStorage(encryption); | ||
const cache = new Cache(options); | ||
const api = new distributed_execution_api_1.DistributedExecutionApi(options); | ||
runDistributedExecution(api, options, context, fileStorage, cache, runGroup, tasks) | ||
.then((r) => __awaiter(void 0, void 0, void 0, function* () { | ||
if (r.commandStatus === 0) { | ||
output.success({ | ||
title: 'Successfully completed running the command.', | ||
bodyLines: [`See run details at ${r.runUrl}`], | ||
}); | ||
} | ||
else { | ||
output.error({ | ||
title: 'Command execution failed.', | ||
bodyLines: [`See run details at ${r.runUrl}`], | ||
}); | ||
} | ||
yield (0, metric_logger_1.submitRunMetrics)(options); | ||
process.exit(r.commandStatus); | ||
})) | ||
.catch((e) => { | ||
output.error({ | ||
title: 'Unable to complete a run.', | ||
bodyLines: [e.message], | ||
}); | ||
if (e.axiosException) { | ||
console.log(e.axiosException); | ||
} | ||
else { | ||
console.log(e); | ||
} | ||
api | ||
.completeRunGroupWithError(runGroup, `Main job terminated with an error: "${e.message}"`) | ||
.finally(() => process.exit(1)); | ||
}); | ||
return new Observable_1.Observable(() => { }); | ||
}; | ||
exports.nxCloudDistributedTasksRunner = nxCloudDistributedTasksRunner; | ||
class TaskOrderer { | ||
constructor(projectGraph, defaultTargetDependencies) { | ||
this.projectGraph = projectGraph; | ||
this.defaultTargetDependencies = defaultTargetDependencies; | ||
} | ||
splitTasksIntoStages(tasks) { | ||
if (tasks.length === 0) | ||
return []; | ||
const stages = []; | ||
const taskGraph = this.createTaskGraph(tasks); | ||
const notStagedTaskIds = new Set(tasks.map((t) => t.id)); | ||
let stageIndex = 0; | ||
// Loop through tasks and try to stage them. As tasks are staged, they are removed from the loop | ||
while (notStagedTaskIds.size > 0) { | ||
const currentStage = (stages[stageIndex] = []); | ||
for (const taskId of notStagedTaskIds) { | ||
let ready = true; | ||
for (const dependency of taskGraph.dependencies[taskId]) { | ||
if (notStagedTaskIds.has(dependency)) { | ||
// dependency has not been staged yet, this task is not ready to be staged. | ||
ready = false; | ||
break; | ||
} | ||
} | ||
// Some dependency still has not been staged, skip it for now, it will be processed again | ||
if (!ready) { | ||
continue; | ||
} | ||
// All the dependencies have been staged, let's stage it. | ||
const task = taskGraph.tasks[taskId]; | ||
currentStage.push(task); | ||
} | ||
// Remove the entire new stage of tasks from the list | ||
for (const task of currentStage) { | ||
notStagedTaskIds.delete(task.id); | ||
} | ||
stageIndex++; | ||
} | ||
return stages; | ||
} | ||
createTaskGraph(tasks) { | ||
const t = new TaskGraphCreator(this.projectGraph, this.defaultTargetDependencies); | ||
return t.createTaskGraph(tasks); | ||
} | ||
} | ||
class TaskGraphCreator { | ||
constructor(projectGraph, defaultTargetDependencies) { | ||
this.projectGraph = projectGraph; | ||
this.defaultTargetDependencies = defaultTargetDependencies; | ||
} | ||
createTaskGraph(tasks) { | ||
const graph = { | ||
roots: [], | ||
tasks: {}, | ||
dependencies: {}, | ||
}; | ||
for (const task of tasks) { | ||
this.addTaskToGraph(task, graph); | ||
const dependencyConfigs = getDependencyConfigs(task.target, this.defaultTargetDependencies, this.projectGraph); | ||
if (!dependencyConfigs) { | ||
continue; | ||
} | ||
this.addTaskDependencies(task, dependencyConfigs, tasks, graph); | ||
} | ||
graph.roots = Object.keys(graph.dependencies).filter((k) => graph.dependencies[k].length === 0); | ||
return graph; | ||
} | ||
addTaskDependencies(task, dependencyConfigs, tasks, graph) { | ||
for (const dependencyConfig of dependencyConfigs) { | ||
if (dependencyConfig.projects === 'self') { | ||
for (const t of tasks) { | ||
if (t.target.project === task.target.project && | ||
t.target.target === dependencyConfig.target) { | ||
graph.dependencies[task.id].push(t.id); | ||
} | ||
} | ||
} | ||
else if (dependencyConfig.projects === 'dependencies') { | ||
const seen = new Set(); | ||
this.addDependencies(task.target.project, dependencyConfig.target, tasks, graph, task.id, seen); | ||
} | ||
} | ||
} | ||
addDependencies(project, target, tasks, graph, taskId, seen) { | ||
seen.add(project); | ||
const dependencies = this.projectGraph.dependencies[project]; | ||
if (dependencies) { | ||
const projectDependencies = dependencies.map((dependency) => dependency.target); | ||
for (const projectDependency of projectDependencies) { | ||
if (seen.has(projectDependency)) { | ||
continue; | ||
} | ||
const dependency = this.findTask({ project: projectDependency, target }, tasks); | ||
if (dependency) { | ||
if (graph.dependencies[taskId].indexOf(dependency.id) === -1) { | ||
graph.dependencies[taskId].push(dependency.id); | ||
} | ||
} | ||
else { | ||
this.addDependencies(projectDependency, target, tasks, graph, taskId, seen); | ||
} | ||
} | ||
} | ||
} | ||
findTask({ project, target }, tasks) { | ||
return tasks.find((t) => t.target.project === project && t.target.target === target); | ||
} | ||
addTaskToGraph(task, graph) { | ||
graph.tasks[task.id] = task; | ||
graph.dependencies[task.id] = []; | ||
} | ||
} | ||
exports.TaskGraphCreator = TaskGraphCreator; | ||
function getDefaultDependencyConfigs(nxJson, runnerOptions) { | ||
var _a, _b; | ||
const defaults = (_a = nxJson.targetDependencies) !== null && _a !== void 0 ? _a : {}; | ||
const strictlyOrderedTargets = runnerOptions | ||
? (_b = runnerOptions.strictlyOrderedTargets) !== null && _b !== void 0 ? _b : ['build'] | ||
: []; | ||
// Strictly Ordered Targets depend on their dependencies | ||
for (const target of strictlyOrderedTargets) { | ||
defaults[target] = defaults[target] || []; | ||
defaults[target].push({ | ||
target, | ||
projects: 'dependencies', | ||
}); | ||
} | ||
return defaults; | ||
} | ||
//# sourceMappingURL=distributed-execution.runner.js.map |
@@ -85,2 +85,10 @@ "use strict"; | ||
} | ||
// Gitlab, unique across all jobs in the instance | ||
if (process.env.CI_JOB_ID) { | ||
return process.env.CI_JOB_ID; | ||
} | ||
// Jenkins | ||
if (process.env.BUILD_TAG) { | ||
return process.env.BUILD_TAG; | ||
} | ||
return extractGitSha(); | ||
@@ -130,2 +138,15 @@ } | ||
} | ||
// Gitlab, merge request flow only | ||
if (process.env.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME) { | ||
return process.env.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME; | ||
} | ||
// Gitlab, branch pipeline flow only | ||
if (process.env.CI_COMMIT_BRANCH) { | ||
return process.env.CI_COMMIT_BRANCH; | ||
} | ||
// Jenkins, this will only be populated in MULTIBRANCH pipelines. | ||
// Remember that if someone asks in support :) | ||
if (process.env.GIT_BRANCH) { | ||
return process.env.GIT_BRANCH; | ||
} | ||
return null; | ||
@@ -132,0 +153,0 @@ } |
{ | ||
"name": "nx-cloud", | ||
"version": "14.0.3", | ||
"version": "14.0.4-beta.1", | ||
"description": "Nx Cloud plugin for Nx", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 7 instances in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Obfuscated code
Supply chain riskObfuscated files are intentionally packed to hide their behavior. This could be a sign of malware.
Found 3 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
252034
3322
2
0
93
3