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