mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-21 00:59:29 +00:00
Set timeout for shooter
This commit is contained in:
parent
44edfc4c4c
commit
3bc8882f3e
2 changed files with 19 additions and 2 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue