|
|
@ -177,6 +177,7 @@ async function uploadChunk(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isRetryableStatusCode(response.statusCode)) {
|
|
|
|
if (isRetryableStatusCode(response.statusCode)) {
|
|
|
|
|
|
|
|
core.debug(`Received ${response.statusCode}, retrying chunk at offset ${start}.`);
|
|
|
|
const retryResponse = await uploadChunkRequest();
|
|
|
|
const retryResponse = await uploadChunkRequest();
|
|
|
|
if (isSuccessStatusCode(retryResponse.statusCode)) {
|
|
|
|
if (isSuccessStatusCode(retryResponse.statusCode)) {
|
|
|
|
return retryResponse;
|
|
|
|
return retryResponse;
|
|
|
@ -199,20 +200,19 @@ async function uploadFile(
|
|
|
|
const responses: IRestResponse<void>[] = [];
|
|
|
|
const responses: IRestResponse<void>[] = [];
|
|
|
|
const fd = fs.openSync(archivePath, "r");
|
|
|
|
const fd = fs.openSync(archivePath, "r");
|
|
|
|
|
|
|
|
|
|
|
|
const concurrency = 4; // # of HTTP requests in parallel
|
|
|
|
const concurrency = Number(process.env["CACHE_UPLOAD_CONCURRENCY"]) ?? 4; // # of HTTP requests in parallel
|
|
|
|
const MAX_CHUNK_SIZE = 32000000; // 32 MB Chunks
|
|
|
|
const MAX_CHUNK_SIZE = Number(process.env["CACHE_UPLOAD_CHUNK_SIZE"]) ?? 32000000; // 32 MB Chunks
|
|
|
|
core.debug(`Concurrency: ${concurrency} and Chunk Size: ${MAX_CHUNK_SIZE}`);
|
|
|
|
core.debug(`Concurrency: ${concurrency} and Chunk Size: ${MAX_CHUNK_SIZE}`);
|
|
|
|
|
|
|
|
|
|
|
|
const parallelUploads = [...new Array(concurrency).keys()];
|
|
|
|
const parallelUploads = [...new Array(concurrency).keys()];
|
|
|
|
core.debug("Awaiting all uploads");
|
|
|
|
core.debug("Awaiting all uploads");
|
|
|
|
let offset = 0;
|
|
|
|
let offset = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
await Promise.all(
|
|
|
|
await Promise.all(
|
|
|
|
parallelUploads.map(async () => {
|
|
|
|
parallelUploads.map(async () => {
|
|
|
|
while (offset < fileSize) {
|
|
|
|
while (offset < fileSize) {
|
|
|
|
const chunkSize =
|
|
|
|
const chunkSize = Math.min(fileSize - offset, MAX_CHUNK_SIZE)
|
|
|
|
offset + MAX_CHUNK_SIZE > fileSize
|
|
|
|
|
|
|
|
? fileSize - offset
|
|
|
|
|
|
|
|
: MAX_CHUNK_SIZE;
|
|
|
|
|
|
|
|
const start = offset;
|
|
|
|
const start = offset;
|
|
|
|
const end = offset + chunkSize - 1;
|
|
|
|
const end = offset + chunkSize - 1;
|
|
|
|
offset += MAX_CHUNK_SIZE;
|
|
|
|
offset += MAX_CHUNK_SIZE;
|
|
|
@ -234,18 +234,9 @@ async function uploadFile(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
fs.closeSync(fd);
|
|
|
|
fs.closeSync(fd);
|
|
|
|
|
|
|
|
|
|
|
|
const failedResponse = responses.find(
|
|
|
|
|
|
|
|
x => !isSuccessStatusCode(x.statusCode)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
if (failedResponse) {
|
|
|
|
|
|
|
|
throw new Error(
|
|
|
|
|
|
|
|
`Cache service responded with ${failedResponse.statusCode} during chunk upload.`
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|