feat: retry requesting control (#15717)

* feat: retry requesting control

* test: fix error handling test
This commit is contained in:
DIYgod
2024-05-26 21:48:29 +08:00
committed by GitHub
parent 4205e8475d
commit d1dd8a53ca
3 changed files with 28 additions and 6 deletions
+15 -1
View File
@@ -23,7 +23,21 @@ const middleware: MiddlewareHandler = async (ctx, next) => {
const isRequesting = await cacheModule.globalCache.get(controlKey);
if (isRequesting === '1') {
throw new RequestInProgressError('This path is currently fetching, please come back later!');
let retryTimes = process.env.NODE_ENV === 'test' ? 1 : 10;
let bypass = false;
while (retryTimes > 0) {
// eslint-disable-next-line no-await-in-loop
await new Promise((resolve) => setTimeout(resolve, process.env.NODE_ENV === 'test' ? 3000 : 6000));
// eslint-disable-next-line no-await-in-loop
if ((await cacheModule.globalCache.get(controlKey)) !== '1') {
bypass = true;
break;
}
retryTimes--;
}
if (!bypass) {
throw new RequestInProgressError('This path is currently fetching, please come back later!');
}
}
const value = await cacheModule.globalCache.get(key);