From 663e76f373526176724b2e411d34176a7cecbec7 Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Mon, 1 Aug 2022 09:55:34 -0400 Subject: [PATCH] Attempt to fix flaky CI --- .../nodejs/src/visualization/genMap.ts | 52 ++++++++++++------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/development/backend/nodejs/src/visualization/genMap.ts b/development/backend/nodejs/src/visualization/genMap.ts index dac6690b..349840db 100644 --- a/development/backend/nodejs/src/visualization/genMap.ts +++ b/development/backend/nodejs/src/visualization/genMap.ts @@ -90,24 +90,36 @@ export function genMap(props: IGenMap) { .on('finish', async () => { console.log("wrote raw image to file://" + fp) - const image = await Jimp.read(fp); // read image: https://github.com/oliver-moran/jimp/tree/master/packages/jimp - - // title - image.print(await Jimp.loadFont(await getBmfPath(BMF_TITLE_RED_STROKE_PATH)), - 10, 20, '全国停贷地图') - - // sub-title - image.print( - await Jimp.loadFont(await getBmfPath(props.themeName?.includes('dark') ? BMF_TITLE_WHITE_PATH : BMF_TITLE_BLACK_PATH)), // 只有黑色主题才需要白色字体 - 10, 50, `截至${new Date().toLocaleDateString()},已涉及${totalCities} 城市, ${totalProperties} 楼盘` - ) - - // footer - image.print(await Jimp.loadFont(await getBmfPath(BMF_FOOTER_PATH)), - 153, height - 24/*footer-size*/ - 2, '开源地址:https://github.com/WeNeedHome') - - await image.write(fp2) - console.log('wrote watermarked image to file://' + fp2) + var numberOfTries = 5 + + while(numberOfTries > 0) { + try{ + const image = await Jimp.read(fp); // read image: https://github.com/oliver-moran/jimp/tree/master/packages/jimp + + // title + image.print(await Jimp.loadFont(await getBmfPath(BMF_TITLE_RED_STROKE_PATH)), + 10, 20, '全国停贷地图') + + // sub-title + image.print( + await Jimp.loadFont(await getBmfPath(props.themeName?.includes('dark') ? BMF_TITLE_WHITE_PATH : BMF_TITLE_BLACK_PATH)), // 只有黑色主题才需要白色字体 + 10, 50, `截至${new Date().toLocaleDateString()},已涉及${totalCities} 城市, ${totalProperties} 楼盘` + ) + + // footer + image.print(await Jimp.loadFont(await getBmfPath(BMF_FOOTER_PATH)), + 153, height - 24/*footer-size*/ - 2, '开源地址:https://github.com/WeNeedHome') + + await image.write(fp2) + console.log('wrote watermarked image to file://' + fp2) + break; + } + catch (e:any){ + numberOfTries-- + await delay(500) + console.log(e,'error, ' + numberOfTries + ' more tries') + } + } }) }) @@ -116,6 +128,10 @@ export function genMap(props: IGenMap) { }) } +function delay(milliseconds : number) { + return new Promise(resolve => setTimeout( resolve, milliseconds)); +} + const availableGoogleThemes: string[] = fs.readdirSync(DATA_CONFIG_GOOGLE_THEME_DIR) const cities: AddressWithCount[] = JSON.parse(fs.readFileSync(DATA_VISUALIZATION_PATH, "utf-8"))