mirror of
https://github.com/actions/cache.git
synced 2025-04-22 03:56:45 +00:00
PR feedback
This commit is contained in:
parent
61f374ae8c
commit
23daa0a638
5 changed files with 40 additions and 49 deletions
|
@ -208,7 +208,7 @@ test("save with large cache outputs warning", async () => {
|
||||||
|
|
||||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
||||||
expect(logWarningMock).toHaveBeenCalledWith(
|
expect(logWarningMock).toHaveBeenCalledWith(
|
||||||
"Cache size of ~4 GB (4294967296 B) is over the 2GB limit, not saving cache."
|
"Cache size of ~4096 MB (4294967296 B) is over the 2GB limit, not saving cache."
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||||
|
|
2
package-lock.json
generated
2
package-lock.json
generated
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "cache",
|
"name": "cache",
|
||||||
"version": "1.0.3",
|
"version": "1.1.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ async function run(): Promise<void> {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const cacheEntry = await cacheHttpClient.getCacheEntry(keys);
|
const cacheEntry = await cacheHttpClient.getCacheEntry(keys);
|
||||||
if (!cacheEntry || !cacheEntry?.archiveLocation) {
|
if (!cacheEntry?.archiveLocation) {
|
||||||
core.info(
|
core.info(
|
||||||
`Cache not found for input keys: ${keys.join(", ")}.`
|
`Cache not found for input keys: ${keys.join(", ")}.`
|
||||||
);
|
);
|
||||||
|
@ -78,7 +78,7 @@ async function run(): Promise<void> {
|
||||||
|
|
||||||
// Download the cache from the cache entry
|
// Download the cache from the cache entry
|
||||||
await cacheHttpClient.downloadCache(
|
await cacheHttpClient.downloadCache(
|
||||||
cacheEntry?.archiveLocation,
|
cacheEntry.archiveLocation,
|
||||||
archivePath
|
archivePath
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ async function run(): Promise<void> {
|
||||||
|
|
||||||
core.debug("Reserving Cache");
|
core.debug("Reserving Cache");
|
||||||
const cacheId = await cacheHttpClient.reserveCache(primaryKey);
|
const cacheId = await cacheHttpClient.reserveCache(primaryKey);
|
||||||
if (cacheId < 0) {
|
if (cacheId == -1) {
|
||||||
core.info(
|
core.info(
|
||||||
`Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.`
|
`Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.`
|
||||||
);
|
);
|
||||||
|
@ -62,13 +62,13 @@ async function run(): Promise<void> {
|
||||||
if (archiveFileSize > fileSizeLimit) {
|
if (archiveFileSize > fileSizeLimit) {
|
||||||
utils.logWarning(
|
utils.logWarning(
|
||||||
`Cache size of ~${Math.round(
|
`Cache size of ~${Math.round(
|
||||||
archiveFileSize / (1024 * 1024 * 1024)
|
archiveFileSize / (1024 * 1024)
|
||||||
)} GB (${archiveFileSize} B) is over the 2GB limit, not saving cache.`
|
)} MB (${archiveFileSize} B) is over the 2GB limit, not saving cache.`
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug("Saving Cache");
|
core.debug(`Saving Cache (ID: ${cacheId})`);
|
||||||
await cacheHttpClient.saveCache(cacheId, archivePath);
|
await cacheHttpClient.saveCache(cacheId, archivePath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
utils.logWarning(error.message);
|
utils.logWarning(error.message);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue