-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add remote-entry script resource retry for retry-plugin (#3321)
- Loading branch information
Showing
9 changed files
with
153 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@module-federation/retry-plugin': patch | ||
'@module-federation/runtime': patch | ||
--- | ||
|
||
feat: add remote-entry script resource retry for retry-plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { defaultRetries, defaultRetryDelay } from './constant'; | ||
import type { ScriptCommonRetryOption } from './types'; | ||
import logger from './logger'; | ||
|
||
export function scriptCommonRetry<T extends (...args: any[]) => void>({ | ||
scriptOption, | ||
moduleInfo, | ||
retryFn, | ||
beforeExecuteRetry = () => {}, | ||
}: ScriptCommonRetryOption) { | ||
return async function (...args: Parameters<T>) { | ||
let retryResponse; | ||
const { retryTimes = defaultRetries, retryDelay = defaultRetryDelay } = | ||
scriptOption || {}; | ||
if ( | ||
(scriptOption?.moduleName && | ||
scriptOption?.moduleName.some( | ||
(m) => moduleInfo.name === m || moduleInfo?.alias === m, | ||
)) || | ||
scriptOption?.moduleName === undefined | ||
) { | ||
let attempts = 0; | ||
while (attempts - 1 < retryTimes) { | ||
try { | ||
beforeExecuteRetry && beforeExecuteRetry(); | ||
retryResponse = await retryFn(...args); | ||
break; | ||
} catch (error) { | ||
attempts++; | ||
if (attempts - 1 >= retryTimes) { | ||
scriptOption?.cb && | ||
(await new Promise( | ||
(resolve) => | ||
scriptOption?.cb && scriptOption?.cb(resolve, error), | ||
)); | ||
throw error; | ||
} | ||
logger.log( | ||
`[ Module Federation RetryPlugin ]: script resource retrying ${attempts} times`, | ||
); | ||
await new Promise((resolve) => setTimeout(resolve, retryDelay)); | ||
} | ||
} | ||
} | ||
return retryResponse; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters