@nrwl/nx-cloud 15.3.1 → 15.3.3-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core/api/error-reporter.api.js +36 -1
- package/lib/core/api/run-group.api.js +73 -1
- package/lib/core/api/run-group.api.js.map +1 -1
- package/lib/core/commands/record-output.js +6 -2
- package/lib/core/commands/record-output.js.map +1 -1
- package/lib/core/commands/upload-and-show-run-details.js +2 -1
- package/lib/core/commands/upload-and-show-run-details.js.map +1 -1
- package/lib/core/file-storage/file-storage.js +1 -1
- package/lib/core/file-storage/file-storage.js.map +1 -1
- package/lib/core/runners/cloud-enabled/cloud-enabled-life-cycle.js +93 -1
- package/lib/core/runners/cloud-enabled/cloud-enabled.runner.js +320 -1
- package/lib/core/runners/cloud-enabled/cloud-enabled.runner.js.map +1 -1
- package/lib/core/runners/cloud-enabled/cloud-remote-cache.js +133 -1
- package/lib/core/runners/cloud-enabled/cloud-run.api.js +168 -1
- package/lib/core/runners/cloud-enabled/id-generator.js +16 -1
- package/lib/core/runners/distributed-agent/distributed-agent.api.js +93 -1
- package/lib/core/runners/distributed-agent/distributed-agent.impl.js +157 -1
- package/lib/core/runners/distributed-agent/execute-tasks.js +114 -1
- package/lib/core/runners/distributed-agent/invoke-tasks-using-nx-imperative-api.js +58 -1
- package/lib/core/runners/distributed-agent/invoke-tasks-using-run-many.js +97 -1
- package/lib/core/runners/distributed-execution/distributed-execution.api.d.ts +1 -1
- package/lib/core/runners/distributed-execution/distributed-execution.api.js +152 -1
- package/lib/core/runners/distributed-execution/distributed-execution.api.js.map +1 -1
- package/lib/core/runners/distributed-execution/distributed-execution.runner.js +118 -1
- package/lib/core/runners/distributed-execution/process-task.js +45 -1
- package/lib/core/runners/distributed-execution/process-tasks.js +67 -1
- package/lib/core/runners/distributed-execution/split-task-graph-into-stages.js +37 -1
- package/lib/core/runners/distributed-execution/task-graph-creator.js +100 -1
- package/lib/utilities/environment.js +8 -2
- package/lib/utilities/environment.js.map +1 -1
- package/lib/utilities/is-private-cloud.d.ts +1 -0
- package/lib/utilities/is-private-cloud.js +30 -0
- package/lib/utilities/is-private-cloud.js.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1,168 @@
|
|
|
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
|
+
// API is not working, don't make the end request
|
|
31
|
+
if (this.messages.apiError)
|
|
32
|
+
return {};
|
|
33
|
+
const recorder = (0, metric_logger_1.createMetricRecorder)('startRun');
|
|
34
|
+
try {
|
|
35
|
+
const request = {
|
|
36
|
+
meta: {
|
|
37
|
+
nxCloudVersion: this.nxCloudVersion(),
|
|
38
|
+
},
|
|
39
|
+
branch: (0, environment_1.getBranch)(),
|
|
40
|
+
runGroup: (0, environment_1.getRunGroup)(),
|
|
41
|
+
ciExecutionId: (0, environment_1.getCIExecutionId)(),
|
|
42
|
+
ciExecutionEnv: (0, environment_1.getCIExecutionEnv)(),
|
|
43
|
+
distributedExecutionId,
|
|
44
|
+
hashes,
|
|
45
|
+
};
|
|
46
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
47
|
+
output.note({
|
|
48
|
+
title: 'RunStart',
|
|
49
|
+
bodyLines: ['\n' + JSON.stringify(request, null, 2)],
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const resp = yield (0, axios_1.printDuration)('RunStart duration', () => (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/runs/start', request)));
|
|
53
|
+
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
|
|
54
|
+
if (resp.data && resp.data.message) {
|
|
55
|
+
this.messages.message = resp.data.message;
|
|
56
|
+
}
|
|
57
|
+
if (!resp.data || !resp.data.urls) {
|
|
58
|
+
this.messages.apiError = `Invalid Nx Cloud response: ${JSON.stringify(resp.data)}`;
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
return resp.data.urls;
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
65
|
+
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
|
|
66
|
+
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
67
|
+
this.messages.apiError = this.messages.extractErrorMessage(e, 'api');
|
|
68
|
+
return {};
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
createReqBody(run, tasks, ciExecutionContext, linkId) {
|
|
73
|
+
const uncompressedReqBody = Object.assign(Object.assign({ meta: {
|
|
74
|
+
nxCloudVersion: this.nxCloudVersion(),
|
|
75
|
+
}, tasks,
|
|
76
|
+
run,
|
|
77
|
+
linkId }, ciExecutionContext), { machineInfo: this.machineInfo });
|
|
78
|
+
return JSON.stringify(uncompressedReqBody);
|
|
79
|
+
}
|
|
80
|
+
endRun(run, tasks, ciExecutionContext, linkId) {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
// API is not working, don't make the end request
|
|
84
|
+
if (this.messages.apiError)
|
|
85
|
+
return false;
|
|
86
|
+
let uncompressedBodyString = this.createReqBody(run, tasks, ciExecutionContext, linkId);
|
|
87
|
+
// if the req body is > 20mb, remove hashDetails
|
|
88
|
+
if (uncompressedBodyString.length > 20 * 1000 * 1000) {
|
|
89
|
+
uncompressedBodyString = this.createReqBody(run, tasks.map((t) => (Object.assign(Object.assign({}, t), { hashDetails: undefined }))), ciExecutionContext, linkId);
|
|
90
|
+
}
|
|
91
|
+
const uncompressedBuffer = Buffer.from(uncompressedBodyString);
|
|
92
|
+
const compressedBuffer = yield (0, util_1.promisify)(zlib_1.gzip)(uncompressedBuffer);
|
|
93
|
+
const recorder = (0, metric_logger_1.createMetricRecorder)('endRun');
|
|
94
|
+
try {
|
|
95
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
96
|
+
const t = tasks.map((tt) => {
|
|
97
|
+
return Object.assign(Object.assign({}, tt), { terminalOutput: tt.terminalOutput
|
|
98
|
+
? `${tt.terminalOutput.slice(0, 20)}...`
|
|
99
|
+
: undefined });
|
|
100
|
+
});
|
|
101
|
+
output.note({
|
|
102
|
+
title: 'RunEnd. Completed tasks',
|
|
103
|
+
bodyLines: ['\n' + JSON.stringify(t, null, 2)],
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
const resp = yield (0, axios_1.printDuration)('RunEnd duration', () => (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/runs/end', compressedBuffer, {
|
|
107
|
+
headers: Object.assign(Object.assign({}, this.apiAxiosInstance.defaults.headers), { 'Content-Encoding': 'gzip', 'Content-Type': 'application/octet-stream' }),
|
|
108
|
+
})));
|
|
109
|
+
if (resp) {
|
|
110
|
+
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
|
|
111
|
+
if (resp.data && resp.data.runUrl && resp.data.status === 'success') {
|
|
112
|
+
this.runContext.runUrl = resp.data.runUrl;
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
if (resp.data && resp.data.status) {
|
|
116
|
+
this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data.message)}`;
|
|
117
|
+
}
|
|
118
|
+
else if (resp.data && typeof resp.data === 'string') {
|
|
119
|
+
if (resp.data !== 'success') {
|
|
120
|
+
this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data)}`;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data)}`;
|
|
125
|
+
}
|
|
126
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
127
|
+
output.note({
|
|
128
|
+
title: 'Invalid end run response',
|
|
129
|
+
bodyLines: [JSON.stringify(resp.data, null, 2)],
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
output.error({
|
|
135
|
+
title: 'Nx Cloud: Unknown Error Occurred',
|
|
136
|
+
bodyLines: [
|
|
137
|
+
'Run completion responded with `undefined`.',
|
|
138
|
+
'Run Details:',
|
|
139
|
+
JSON.stringify(run, null, 2),
|
|
140
|
+
'Stack Trace:',
|
|
141
|
+
JSON.stringify(new Error().stack, null, 2),
|
|
142
|
+
],
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
catch (ee) {
|
|
148
|
+
recorder.recordMetric(((_a = ee === null || ee === void 0 ? void 0 : ee.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
149
|
+
? (0, metric_logger_1.mapRespToPerfEntry)(ee.axiosException.response)
|
|
150
|
+
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
151
|
+
const e = (_b = ee.axiosException) !== null && _b !== void 0 ? _b : ee;
|
|
152
|
+
this.messages.apiError = this.messages.extractErrorMessage(e, 'api');
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
nxCloudVersion() {
|
|
158
|
+
try {
|
|
159
|
+
const v = JSON.parse((0, fs_1.readFileSync)(`package.json`).toString());
|
|
160
|
+
return v.devDependencies['@nrwl/nx-cloud'];
|
|
161
|
+
}
|
|
162
|
+
catch (e) {
|
|
163
|
+
return 'unknown';
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
exports.CloudRunApi = CloudRunApi;
|
|
168
|
+
//# 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,93 @@
|
|
|
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, branch, runGroup, ciExecutionId, ciExecutionEnv, agentName) {
|
|
19
|
+
this.branch = branch;
|
|
20
|
+
this.runGroup = runGroup;
|
|
21
|
+
this.ciExecutionId = ciExecutionId;
|
|
22
|
+
this.ciExecutionEnv = ciExecutionEnv;
|
|
23
|
+
this.agentName = agentName;
|
|
24
|
+
this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options);
|
|
25
|
+
}
|
|
26
|
+
tasks(executionId, statusCode, completedTasks, targets) {
|
|
27
|
+
var _a;
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const recorder = (0, metric_logger_1.createMetricRecorder)('dtePollTasks');
|
|
30
|
+
try {
|
|
31
|
+
const res = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/tasks', {
|
|
32
|
+
runGroup: this.runGroup,
|
|
33
|
+
ciExecutionId: this.ciExecutionId,
|
|
34
|
+
ciExecutionEnv: this.ciExecutionEnv,
|
|
35
|
+
agentName: this.agentName,
|
|
36
|
+
executionId,
|
|
37
|
+
statusCode,
|
|
38
|
+
completedTasks,
|
|
39
|
+
targets,
|
|
40
|
+
}));
|
|
41
|
+
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(res));
|
|
42
|
+
return res.data;
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
46
|
+
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
|
|
47
|
+
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
48
|
+
throw e;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
completeRunGroupWithError(error) {
|
|
53
|
+
var _a;
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
56
|
+
output.note({
|
|
57
|
+
title: 'Completing with an error',
|
|
58
|
+
bodyLines: [
|
|
59
|
+
`ciExecutionId: ${this.ciExecutionId}`,
|
|
60
|
+
`ciExecutionEnv: ${this.ciExecutionEnv}`,
|
|
61
|
+
`runGroup: ${this.runGroup}`,
|
|
62
|
+
`error: ${error}`,
|
|
63
|
+
],
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const recorder = (0, metric_logger_1.createMetricRecorder)('completeRunGroup');
|
|
67
|
+
try {
|
|
68
|
+
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/complete-run-group', {
|
|
69
|
+
branch: this.branch,
|
|
70
|
+
runGroup: this.runGroup,
|
|
71
|
+
ciExecutionId: this.ciExecutionId,
|
|
72
|
+
ciExecutionEnv: this.ciExecutionEnv,
|
|
73
|
+
agentName: this.agentName,
|
|
74
|
+
criticalErrorMessage: error,
|
|
75
|
+
}));
|
|
76
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
77
|
+
output.note({
|
|
78
|
+
title: 'Completed run group with an error',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
85
|
+
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
|
|
86
|
+
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
87
|
+
console.error(e);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.DistributedAgentApi = DistributedAgentApi;
|
|
93
|
+
//# sourceMappingURL=distributed-agent.api.js.map
|
|
@@ -1 +1,157 @@
|
|
|
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.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 branch = (0, environment_1.getBranch)();
|
|
42
|
+
const runGroup = (0, environment_1.getRunGroup)();
|
|
43
|
+
const ciExecutionId = (0, environment_1.getCIExecutionId)();
|
|
44
|
+
const ciExecutionEnv = (0, environment_1.getCIExecutionEnv)();
|
|
45
|
+
if (!(0, print_run_group_error_1.canDetectRunGroup)(runGroup, ciExecutionId)) {
|
|
46
|
+
(0, print_run_group_error_1.printRunGroupError)();
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
if (args.targets && args.targets.length) {
|
|
50
|
+
output.note({
|
|
51
|
+
title: `Starting an agent for running Nx target(s) [${args.targets.join(', ')}]`,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
output.note({
|
|
56
|
+
title: 'Starting an agent for running Nx tasks',
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const defaultRunnerConfig = JSON.parse(stripJsonComments((0, fs_1.readFileSync)(`${workspaceRoot}/nx.json`).toString())).tasksRunnerOptions.default;
|
|
60
|
+
if (defaultRunnerConfig.runner !== '@nrwl/nx-cloud') {
|
|
61
|
+
(0, print_invalid_runner_error_1.printInvalidRunnerError)();
|
|
62
|
+
return process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
const options = defaultRunnerConfig.options;
|
|
65
|
+
if (args.targets &&
|
|
66
|
+
args.targets.some((target) => { var _a; return !((_a = options.cacheableOperations) === null || _a === void 0 ? void 0 : _a.includes(target)); })) {
|
|
67
|
+
const wrongTargets = args.targets.filter((target) => { var _a; return !((_a = options.cacheableOperations) === null || _a === void 0 ? void 0 : _a.includes(target)); });
|
|
68
|
+
(0, print_cacheable_targets_error_1.printCacheableTargetsError)(wrongTargets);
|
|
69
|
+
return process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
const agentName = getAgentName();
|
|
72
|
+
const api = new distributed_agent_api_1.DistributedAgentApi(options, branch, runGroup, ciExecutionId, ciExecutionEnv, agentName);
|
|
73
|
+
createAgentLockfileAndSetUpListeners(api, options, agentName);
|
|
74
|
+
const encryption = new e2e_encryption_1.E2EEncryption(environment_1.ENCRYPTION_KEY || options.encryptionKey);
|
|
75
|
+
const errorReporter = new error_reporter_api_1.ErrorReporterApi(options);
|
|
76
|
+
const dteArtifactStorage = new dte_artifact_storage_1.DteArtifactStorage(new file_storage_1.FileStorage(encryption, errorReporter, options, 'dte-agent'), (0, environment_1.getNxCacheDirectory)(options));
|
|
77
|
+
const invokeTasks = initTasksRunner
|
|
78
|
+
? yield (0, invoke_tasks_using_nx_imperative_api_1.invokeTasksUsingNxImperativeApi)(options)
|
|
79
|
+
: yield (0, invoke_tasks_using_run_many_1.invokeTasksUsingRunMany)(options);
|
|
80
|
+
return (0, execute_tasks_1.executeTasks)(agentName, api, dteArtifactStorage, invokeTasks, args.targets)
|
|
81
|
+
.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
yield (0, metric_logger_1.submitRunMetrics)(options);
|
|
83
|
+
return res;
|
|
84
|
+
}))
|
|
85
|
+
.catch((e) => __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
yield api.completeRunGroupWithError(`Critical Error in Agent: "${e.message}"`);
|
|
87
|
+
throw e;
|
|
88
|
+
}));
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
exports.startAgent = startAgent;
|
|
92
|
+
function getAgentName() {
|
|
93
|
+
if (process.env.NX_AGENT_NAME !== undefined) {
|
|
94
|
+
return process.env.NX_AGENT_NAME;
|
|
95
|
+
}
|
|
96
|
+
else if (process.env.CIRCLECI !== undefined && process.env.CIRCLE_STAGE) {
|
|
97
|
+
return process.env.CIRCLE_STAGE;
|
|
98
|
+
}
|
|
99
|
+
else if (process.env.CIRCLECI !== undefined && process.env.CIRCLE_JOB) {
|
|
100
|
+
return process.env.CIRCLE_JOB;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
return `Agent ${Math.floor(Math.random() * 100000)}`;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function createAgentLockfileAndSetUpListeners(api, options, agentName) {
|
|
107
|
+
const cacheDirectory = (0, environment_1.getNxCacheDirectory)(options);
|
|
108
|
+
const lockFileDirectory = `${cacheDirectory}/lockfiles`;
|
|
109
|
+
const lockFilePath = `${lockFileDirectory}/${agentName}.lock`;
|
|
110
|
+
if (!(0, fs_1.existsSync)(lockFileDirectory)) {
|
|
111
|
+
(0, fs_1.mkdirSync)(lockFileDirectory, { recursive: true });
|
|
112
|
+
}
|
|
113
|
+
// Check for other agents' lockfiles and warn if exist
|
|
114
|
+
const lockFiles = (0, fs_1.readdirSync)(lockFileDirectory);
|
|
115
|
+
if (lockFiles.length) {
|
|
116
|
+
// Check to make sure the current agent name is not in use (only 1/100000 ^ 2 chance of this)
|
|
117
|
+
if (lockFiles.includes(`${agentName}.lock`)) {
|
|
118
|
+
output.error({
|
|
119
|
+
title: 'Duplicate Agent ID Detected',
|
|
120
|
+
bodyLines: [
|
|
121
|
+
'We have detected another agent with this ID running in this workspace. This should not happen.',
|
|
122
|
+
'',
|
|
123
|
+
'End all currently running agents, run "npx nx-cloud clean-up-agents", and try again.',
|
|
124
|
+
],
|
|
125
|
+
});
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
output.warn({
|
|
129
|
+
title: 'Other Nx Cloud Agents Detected',
|
|
130
|
+
bodyLines: [
|
|
131
|
+
'We have detected other agents running in this workspace. This can cause unexpected behavior.',
|
|
132
|
+
'',
|
|
133
|
+
'This can also be a false positive caused by agents that did not shut down correctly.',
|
|
134
|
+
'If you believe this is the case, run "npx nx-cloud clean-up-agents".',
|
|
135
|
+
],
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
(0, fs_1.writeFileSync)(lockFilePath, '');
|
|
139
|
+
process.on('exit', (code) => {
|
|
140
|
+
cleanupAgentLockfile(lockFilePath, code);
|
|
141
|
+
});
|
|
142
|
+
process.on('SIGTERM', () => __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
yield api.completeRunGroupWithError('Agent was terminated via SIGTERM');
|
|
144
|
+
cleanupAgentLockfile(lockFilePath, 1);
|
|
145
|
+
}));
|
|
146
|
+
process.on('SIGINT', () => __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
yield api.completeRunGroupWithError('Agent was terminated via SIGINT');
|
|
148
|
+
cleanupAgentLockfile(lockFilePath, 1);
|
|
149
|
+
}));
|
|
150
|
+
}
|
|
151
|
+
function cleanupAgentLockfile(lockFilePath, code) {
|
|
152
|
+
if ((0, fs_1.existsSync)(lockFilePath)) {
|
|
153
|
+
(0, fs_1.unlinkSync)(lockFilePath);
|
|
154
|
+
process.exit(code);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=distributed-agent.impl.js.map
|
|
@@ -1 +1,114 @@
|
|
|
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.executeTasks = void 0;
|
|
13
|
+
const create_unchanged_value_timeout_1 = require("../../../utilities/create-unchanged-value-timeout");
|
|
14
|
+
const environment_1 = require("../../../utilities/environment");
|
|
15
|
+
const waiter_1 = require("../../../utilities/waiter");
|
|
16
|
+
const { output } = require('../../../utilities/nx-imports');
|
|
17
|
+
function executeTasks(agentName, api, dteArtifactStorage, invokeTasks, targets) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
let completedStatusCode = 0;
|
|
20
|
+
let apiResponse = null;
|
|
21
|
+
const failIfSameTasksAfterTimeout = (0, create_unchanged_value_timeout_1.createUnchangedValueTimeout)({
|
|
22
|
+
title: `No new messages received after ${environment_1.NO_MESSAGES_TIMEOUT / 1000} seconds`,
|
|
23
|
+
timeout: environment_1.NO_MESSAGES_TIMEOUT,
|
|
24
|
+
});
|
|
25
|
+
const waiter = new waiter_1.Waiter();
|
|
26
|
+
let completedTasks = [];
|
|
27
|
+
const startTime = new Date();
|
|
28
|
+
let executedAnyTasks = false;
|
|
29
|
+
const processedTasks = {};
|
|
30
|
+
while (true) {
|
|
31
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
32
|
+
output.note({
|
|
33
|
+
title: `${agentName} fetching tasks...`,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
apiResponse = yield api.tasks(apiResponse ? apiResponse.executionId : null, completedStatusCode, completedTasks, targets);
|
|
37
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
38
|
+
output.note({
|
|
39
|
+
title: `${agentName} received an API Response`,
|
|
40
|
+
bodyLines: [
|
|
41
|
+
`completed: ${apiResponse.completed}`,
|
|
42
|
+
`status: ${apiResponse.status}`,
|
|
43
|
+
`retryDuring: ${apiResponse.retryDuring}`,
|
|
44
|
+
`executionId: ${apiResponse.executionId}`,
|
|
45
|
+
`number of tasks: ${apiResponse.tasks.length}`,
|
|
46
|
+
`error: ${apiResponse.criticalErrorMessage}`,
|
|
47
|
+
`maxParallel: ${apiResponse.maxParallel}`,
|
|
48
|
+
],
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (apiResponse.criticalErrorMessage) {
|
|
52
|
+
output.error({
|
|
53
|
+
title: 'Distributed Execution Terminated',
|
|
54
|
+
bodyLines: ['Error:', apiResponse.criticalErrorMessage],
|
|
55
|
+
});
|
|
56
|
+
process.exit(0);
|
|
57
|
+
}
|
|
58
|
+
// run group is completed but it might be a rerun
|
|
59
|
+
// we will try several times before going further and
|
|
60
|
+
// completed the response
|
|
61
|
+
// we only do it if we haven't executed any tasks
|
|
62
|
+
if ((apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.retryDuring) &&
|
|
63
|
+
(apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.retryDuring) !== 0 &&
|
|
64
|
+
!executedAnyTasks &&
|
|
65
|
+
new Date().getTime() - startTime.getTime() > apiResponse.retryDuring) {
|
|
66
|
+
yield waiter.wait();
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if ((apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.status) !== undefined) {
|
|
70
|
+
if (apiResponse.status === 'RUN_GROUP_COMPLETED' ||
|
|
71
|
+
apiResponse.status === 'NO_FURTHER_TASKS_TO_RUN') {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else if (apiResponse.completed) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// if status is present that use the status instead of completed, otherwise use completed
|
|
79
|
+
failIfSameTasksAfterTimeout(apiResponse.tasks.map((t) => t.taskId).join(''));
|
|
80
|
+
if (!apiResponse.executionId) {
|
|
81
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
82
|
+
output.note({
|
|
83
|
+
title: `${agentName} waiting...`,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
yield waiter.wait();
|
|
87
|
+
completedStatusCode = 0;
|
|
88
|
+
completedTasks = [];
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
waiter.reset();
|
|
92
|
+
executedAnyTasks = true;
|
|
93
|
+
if (apiResponse.completedTasks) {
|
|
94
|
+
for (const t of apiResponse.completedTasks) {
|
|
95
|
+
if (processedTasks[t.taskId])
|
|
96
|
+
continue;
|
|
97
|
+
output.note({
|
|
98
|
+
title: `${agentName} downloading artifacts for ${t.taskId} Hash: ${t.hash} Url: ${t.url}`,
|
|
99
|
+
});
|
|
100
|
+
yield dteArtifactStorage.retrieveAndExtract(t.hash, t.url);
|
|
101
|
+
processedTasks[t.taskId] = true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const r = yield invokeTasks(apiResponse.executionId, apiResponse.tasks, apiResponse.maxParallel);
|
|
105
|
+
for (const t of r.completedTasks) {
|
|
106
|
+
processedTasks[t.taskId] = true;
|
|
107
|
+
}
|
|
108
|
+
completedStatusCode = r.completedStatusCode;
|
|
109
|
+
completedTasks = r.completedTasks;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
exports.executeTasks = executeTasks;
|
|
114
|
+
//# sourceMappingURL=execute-tasks.js.map
|