mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 12:57:46 +00:00
Add retry logic for when a probe finds the Vercel preview page (#11473)
We sometimes fail a probe check because we're still seeing this page: <img width="1086" alt="Screenshot 2024-04-19 at 3 11 17 PM" src="https://github.com/vercel/vercel/assets/5414297/8bc92b2d-d720-4970-8f72-7804bb4e91ce"> This just adds some retry logic before proceeding. If we still see the page after 10 tries it errors
This commit is contained in:
@@ -178,7 +178,32 @@ async function runProbe(probe, deploymentId, deploymentUrl, ctx) {
|
||||
fetchOpts.headers['content-type'] = 'application/json';
|
||||
fetchOpts.body = JSON.stringify(probe.body);
|
||||
}
|
||||
const { text, resp } = await fetchDeploymentUrl(probeUrl, fetchOpts);
|
||||
let result = await fetchDeploymentUrl(probeUrl, fetchOpts);
|
||||
|
||||
// If we receive the preview page from Vercel, the real page should appear momentarily,
|
||||
// retry a few times before running the probe checks
|
||||
const checkForPreviewPage = text => {
|
||||
return text.includes('This page will update once the build completes');
|
||||
};
|
||||
let isShowingBuildPreviewPage = checkForPreviewPage(result.text);
|
||||
for (let retryCount = 0; retryCount < 10; retryCount++) {
|
||||
if (!isShowingBuildPreviewPage) {
|
||||
break;
|
||||
} else {
|
||||
result = await fetchDeploymentUrl(probeUrl, fetchOpts);
|
||||
isShowingBuildPreviewPage = checkForPreviewPage(result.text);
|
||||
if (!isShowingBuildPreviewPage) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
await new Promise(r => setTimeout(r, 1000));
|
||||
}
|
||||
if (isShowingBuildPreviewPage) {
|
||||
throw new Error(`Timed out while waiting for preview page to be replaced`);
|
||||
}
|
||||
|
||||
const { text, resp } = result;
|
||||
|
||||
logWithinTest('finished testing', JSON.stringify(probe));
|
||||
|
||||
let hadTest = false;
|
||||
|
||||
Reference in New Issue
Block a user