Skip to content

Commit 7b06581

Browse files
authored
Merge pull request #961 from ocaml/backoff
Use exponential-backoff for cache restore/save
2 parents a29aba4 + 6a4f253 commit 7b06581

8 files changed

Lines changed: 1310 additions & 7 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
async function restoreCache(
2+
key: string,
3+
restoreKeys: string[],
4+
paths: string[],
5+
options?: DownloadOptions,
6+
) {
7+
if (!cache.isFeatureAvailable()) {
8+
core.info("Actions cache service feature is unavailable");
9+
return;
10+
}
11+
try {
12+
const cacheKey = await cache.restoreCache(paths, key, restoreKeys, options);
13+
if (cacheKey) {
14+
core.info(`Cache restored from key: ${cacheKey}`);
15+
} else {
16+
core.info(
17+
`Cache is not found for input keys: ${[key, ...restoreKeys].join(", ")}`,
18+
);
19+
}
20+
return cacheKey;
21+
} catch (error) {
22+
if (error instanceof Error) {
23+
core.info(`Cache restore error: ${error.message}`);
24+
} else if (error instanceof AggregateError) {
25+
core.info(
26+
`Cache restore network error: ${error.code || "unknown error"}`,
27+
);
28+
} else {
29+
core.info(`Cache restore unknown error: ${String(error)}`);
30+
}
31+
core.notice(
32+
"An internal error has occurred in cache backend. Please check https://www.githubstatus.com for any ongoing issue in actions.",
33+
);
34+
return;
35+
}
36+
}
37+
38+
async function saveCache(key: string, paths: string[]) {
39+
if (!cache.isFeatureAvailable()) {
40+
core.info("Actions cache service feature is unavailable");
41+
return;
42+
}
43+
try {
44+
await cache.saveCache(paths, key);
45+
} catch (error) {
46+
if (error instanceof Error) {
47+
core.info(`Cache save error: ${error.message}`);
48+
} else if (error instanceof AggregateError) {
49+
core.info(`Cache save network error: ${error.code || "unknown error"}`);
50+
} else {
51+
core.info(`Cache save unknown error: ${String(error)}`);
52+
}
53+
core.notice(
54+
"An internal error has occurred in cache backend. Please check https://www.githubstatus.com for any ongoing issue in actions.",
55+
);
56+
}
57+
}

dist/LICENSE.txt

Lines changed: 206 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)