|
|
@ -2246,19 +2246,60 @@ function getCacheVersion(compressionMethod) {
|
|
|
|
.digest("hex");
|
|
|
|
.digest("hex");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.getCacheVersion = getCacheVersion;
|
|
|
|
exports.getCacheVersion = getCacheVersion;
|
|
|
|
|
|
|
|
function retry(name, method, getStatusCode, getReturnValue, isSuccessStatusCode, isRetryableStatusCode, maxAttempts = 2) {
|
|
|
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
|
|
|
let response = undefined;
|
|
|
|
|
|
|
|
let statusCode = undefined;
|
|
|
|
|
|
|
|
let isRetryable = false;
|
|
|
|
|
|
|
|
let errorMessage = "";
|
|
|
|
|
|
|
|
let attempt = 1;
|
|
|
|
|
|
|
|
while (attempt <= maxAttempts) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
response = yield method();
|
|
|
|
|
|
|
|
statusCode = getStatusCode(response);
|
|
|
|
|
|
|
|
if (isSuccessStatusCode(statusCode)) {
|
|
|
|
|
|
|
|
return getReturnValue(response);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
isRetryable = isRetryableStatusCode(statusCode);
|
|
|
|
|
|
|
|
errorMessage = `Cache service responded with ${statusCode}`;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (error) {
|
|
|
|
|
|
|
|
isRetryable = true;
|
|
|
|
|
|
|
|
errorMessage = error.message;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
core.debug(`${name} - Attempt ${attempt} of ${maxAttempts} failed with error: ${errorMessage}`);
|
|
|
|
|
|
|
|
if (!isRetryable) {
|
|
|
|
|
|
|
|
core.debug(`${name} - Error is not retryable`);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
attempt++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
throw Error(`${name} failed: ${errorMessage}`);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.retry = retry;
|
|
|
|
|
|
|
|
function retryTypedResponse(name, method, maxAttempts = 2) {
|
|
|
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
|
|
|
return yield retry(name, method, (response) => response.statusCode, (response) => response, isSuccessStatusCode, isRetryableStatusCode, maxAttempts);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.retryTypedResponse = retryTypedResponse;
|
|
|
|
|
|
|
|
function retryHttpClientResponse(name, method, maxAttempts = 2) {
|
|
|
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
|
|
|
return yield retry(name, method, (response) => response.message.statusCode, (response) => response, isSuccessStatusCode, isRetryableStatusCode, maxAttempts);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.retryHttpClientResponse = retryHttpClientResponse;
|
|
|
|
function getCacheEntry(keys, options) {
|
|
|
|
function getCacheEntry(keys, options) {
|
|
|
|
var _a, _b;
|
|
|
|
var _a, _b;
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
const httpClient = createHttpClient();
|
|
|
|
const httpClient = createHttpClient();
|
|
|
|
const version = getCacheVersion((_a = options) === null || _a === void 0 ? void 0 : _a.compressionMethod);
|
|
|
|
const version = getCacheVersion((_a = options) === null || _a === void 0 ? void 0 : _a.compressionMethod);
|
|
|
|
const resource = `cache?keys=${encodeURIComponent(keys.join(","))}&version=${version}`;
|
|
|
|
const resource = `cache?keys=${encodeURIComponent(keys.join(","))}&version=${version}`;
|
|
|
|
const response = yield httpClient.getJson(getCacheApiUrl(resource));
|
|
|
|
const response = yield retryTypedResponse("getCacheEntry", () => httpClient.getJson(getCacheApiUrl(resource)));
|
|
|
|
if (response.statusCode === 204) {
|
|
|
|
if (response.statusCode === 204) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!isSuccessStatusCode(response.statusCode)) {
|
|
|
|
|
|
|
|
throw new Error(`Cache service responded with ${response.statusCode}`);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const cacheResult = response.result;
|
|
|
|
const cacheResult = response.result;
|
|
|
|
const cacheDownloadUrl = (_b = cacheResult) === null || _b === void 0 ? void 0 : _b.archiveLocation;
|
|
|
|
const cacheDownloadUrl = (_b = cacheResult) === null || _b === void 0 ? void 0 : _b.archiveLocation;
|
|
|
|
if (!cacheDownloadUrl) {
|
|
|
|
if (!cacheDownloadUrl) {
|
|
|
@ -2326,7 +2367,7 @@ function getContentRange(start, end) {
|
|
|
|
// Content-Range: bytes 0-199/*
|
|
|
|
// Content-Range: bytes 0-199/*
|
|
|
|
return `bytes ${start}-${end}/*`;
|
|
|
|
return `bytes ${start}-${end}/*`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function uploadChunk(httpClient, resourceUrl, data, start, end) {
|
|
|
|
function uploadChunk(httpClient, resourceUrl, openStream, start, end) {
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
core.debug(`Uploading chunk of size ${end -
|
|
|
|
core.debug(`Uploading chunk of size ${end -
|
|
|
|
start +
|
|
|
|
start +
|
|
|
@ -2336,20 +2377,9 @@ function uploadChunk(httpClient, resourceUrl, data, start, end) {
|
|
|
|
"Content-Range": getContentRange(start, end)
|
|
|
|
"Content-Range": getContentRange(start, end)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
const uploadChunkRequest = () => __awaiter(this, void 0, void 0, function* () {
|
|
|
|
const uploadChunkRequest = () => __awaiter(this, void 0, void 0, function* () {
|
|
|
|
return yield httpClient.sendStream("PATCH", resourceUrl, data, additionalHeaders);
|
|
|
|
return yield httpClient.sendStream("PATCH", resourceUrl, openStream(), additionalHeaders);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
const response = yield uploadChunkRequest();
|
|
|
|
yield retryHttpClientResponse(`uploadChunk (start: ${start}, end: ${end})`, uploadChunkRequest);
|
|
|
|
if (isSuccessStatusCode(response.message.statusCode)) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isRetryableStatusCode(response.message.statusCode)) {
|
|
|
|
|
|
|
|
core.debug(`Received ${response.message.statusCode}, retrying chunk at offset ${start}.`);
|
|
|
|
|
|
|
|
const retryResponse = yield uploadChunkRequest();
|
|
|
|
|
|
|
|
if (isSuccessStatusCode(retryResponse.message.statusCode)) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error(`Cache service responded with ${response.message.statusCode} during chunk upload.`);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function parseEnvNumber(key) {
|
|
|
|
function parseEnvNumber(key) {
|
|
|
@ -2379,13 +2409,12 @@ function uploadFile(httpClient, cacheId, archivePath) {
|
|
|
|
const start = offset;
|
|
|
|
const start = offset;
|
|
|
|
const end = offset + chunkSize - 1;
|
|
|
|
const end = offset + chunkSize - 1;
|
|
|
|
offset += MAX_CHUNK_SIZE;
|
|
|
|
offset += MAX_CHUNK_SIZE;
|
|
|
|
const chunk = fs.createReadStream(archivePath, {
|
|
|
|
yield uploadChunk(httpClient, resourceUrl, () => fs.createReadStream(archivePath, {
|
|
|
|
fd,
|
|
|
|
fd,
|
|
|
|
start,
|
|
|
|
start,
|
|
|
|
end,
|
|
|
|
end,
|
|
|
|
autoClose: false
|
|
|
|
autoClose: false
|
|
|
|
});
|
|
|
|
}), start, end);
|
|
|
|
yield uploadChunk(httpClient, resourceUrl, chunk, start, end);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})));
|
|
|
|
})));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -3642,6 +3671,12 @@ class HttpClientResponse {
|
|
|
|
this.message.on('data', (chunk) => {
|
|
|
|
this.message.on('data', (chunk) => {
|
|
|
|
output = Buffer.concat([output, chunk]);
|
|
|
|
output = Buffer.concat([output, chunk]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.message.on('aborted', () => {
|
|
|
|
|
|
|
|
reject("Request was aborted or closed prematurely");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
this.message.on('timeout', (socket) => {
|
|
|
|
|
|
|
|
reject("Request timed out");
|
|
|
|
|
|
|
|
});
|
|
|
|
this.message.on('end', () => {
|
|
|
|
this.message.on('end', () => {
|
|
|
|
resolve(output.toString());
|
|
|
|
resolve(output.toString());
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -3763,6 +3798,7 @@ class HttpClient {
|
|
|
|
let response;
|
|
|
|
let response;
|
|
|
|
while (numTries < maxTries) {
|
|
|
|
while (numTries < maxTries) {
|
|
|
|
response = await this.requestRaw(info, data);
|
|
|
|
response = await this.requestRaw(info, data);
|
|
|
|
|
|
|
|
|
|
|
|
// Check if it's an authentication challenge
|
|
|
|
// Check if it's an authentication challenge
|
|
|
|
if (response && response.message && response.message.statusCode === HttpCodes.Unauthorized) {
|
|
|
|
if (response && response.message && response.message.statusCode === HttpCodes.Unauthorized) {
|
|
|
|
let authenticationHandler;
|
|
|
|
let authenticationHandler;
|
|
|
@ -3874,6 +3910,7 @@ class HttpClient {
|
|
|
|
req.on('error', function (err) {
|
|
|
|
req.on('error', function (err) {
|
|
|
|
// err has statusCode property
|
|
|
|
// err has statusCode property
|
|
|
|
// res should have headers
|
|
|
|
// res should have headers
|
|
|
|
|
|
|
|
console.log(`Caught error on request: ${err}`);
|
|
|
|
handleResult(err, null);
|
|
|
|
handleResult(err, null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
if (data && typeof (data) === 'string') {
|
|
|
|
if (data && typeof (data) === 'string') {
|
|
|
|