Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to fix flaky CI #1066

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 34 additions & 18 deletions development/backend/nodejs/src/visualization/genMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
}
})

})
Expand All @@ -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"))
Expand Down