Set timeout for shooter

This commit is contained in:
Jordan Eldredge 2021-10-17 20:27:07 -07:00
parent 44edfc4c4c
commit 3bc8882f3e
2 changed files with 19 additions and 2 deletions

View file

@ -4,6 +4,7 @@ const puppeteer = require("puppeteer");
const imagemin = require("imagemin");
const imageminOptipng = require("imagemin-optipng");
const Skins = require("./data/skins");
const { throwAfter } = require("./utils");
function min(imgPath) {
return imagemin([imgPath], path.dirname(imgPath), {
@ -61,9 +62,19 @@ export default class Shooter {
}
}
async takeScreenshot(skin, screenshotPath, { minify = false, md5 }) {
async takeScreenshot(
skin,
screenshotPath,
{ minify = false, timeout = 30000, md5 }
) {
try {
await this._takeScreenshot(skin, screenshotPath, { minify });
await Promise.race([
this._takeScreenshot(skin, screenshotPath, { minify }),
throwAfter(
`Screenshot did not complete within ${timeout / 1000} seconds.`,
timeout
),
]);
} catch (e) {
await Skins.recordScreenshotUpdate(
md5,

View file

@ -21,3 +21,9 @@ export function chunk<T>(items: T[], chunkSize: number): T[][] {
export const MD5_REGEX = /([a-fA-F0-9]{32})/;
export const TWEET_SNOWFLAKE_REGEX = /([0-9]{19})/;
export function throwAfter(message, ms) {
return new Promise((resolve, reject) => {
setTimeout(() => reject(new Error(message)), ms);
});
}