Skip to content

Commit

Permalink
Merge pull request #1184 from github/edoardo/trap-telemetry-followup
Browse files Browse the repository at this point in the history
Use `util.promisify` instead of manually constructing promise
  • Loading branch information
edoardopirovano authored Aug 16, 2022
2 parents 8a4437a + 016a5e3 commit b0d61cf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 32 deletions.
29 changes: 13 additions & 16 deletions lib/trap-caching.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/trap-caching.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 12 additions & 15 deletions src/trap-caching.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from "fs";
import * as path from "path";
import { promisify } from "util";

import * as cache from "@actions/cache";
import getFolderSize from "get-folder-size";
Expand Down Expand Up @@ -188,21 +189,17 @@ export async function getTotalCacheSize(
trapCaches: Partial<Record<Language, string>>,
logger: Logger
): Promise<number> {
const sizes = await Promise.all(
Object.values(trapCaches).map(async (cacheDir) => {
return new Promise<number>((resolve) => {
getFolderSize(cacheDir, (err, size) => {
if (err) {
logger.warning(`Error getting size of ${cacheDir}: ${err}`);
resolve(0);
} else {
resolve(size);
}
});
});
})
);
return sizes.reduce((a, b) => a + b, 0);
try {
const sizes = await Promise.all(
Object.values(trapCaches).map(async (cacheDir) => {
return promisify<string, number>(getFolderSize)(cacheDir);
})
);
return sizes.reduce((a, b) => a + b, 0);
} catch (e) {
logger.warning(`Encountered an error while getting TRAP cache size: ${e}`);
return 0;
}
}

async function cacheKey(
Expand Down

0 comments on commit b0d61cf

Please sign in to comment.