-
Notifications
You must be signed in to change notification settings - Fork 75
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
feat(contentful): memoizer #BOT-467 #1639
Conversation
2b51f0d
to
f454e41
Compare
f454e41
to
313d221
Compare
BOT-467 mitigate Contentful outages with inmemory cache
In 2021/6/8 & 2021/6/9 contentful was down during 1h, which caused all our bots using this CMS to stop working. We'll start with a simple memoization (lazy in memory cache) In the future maybe we can:
|
export function fallbackStrategy( | ||
usingFallback: (functName: string, args: any[], error: any) => Promise<void> | ||
): MemoizerStrategy { | ||
return async <Args extends any[], Return>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you no need to put again extends any[]
in this type? I understand that Args will extend it as you have typed it as MemoizerStrategy, could be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I typed fallbackStrategy as MemoizerStrategy for the compiler to verify that the lambda I retry complies with this type, but the lambda is not defined to be of this type (generics arguments must always be explicit, otherwise changing their names in the definition would break all usages)
func: (...args: Args) => Promise<Return>, | ||
...args: Args | ||
) => { | ||
// return func(...args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, done in ee9efdb
const cache: Cache<Return> = this.cacheFactory() | ||
const f = (...args: Args) => | ||
this.strategy<Args, Return>(cache, this.normalizer, func, ...args) | ||
// f.cache = cache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, done in ee9efdb
51bcd2b
to
7ff7245
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 👏 Just one doubt in the tests
Use memoization to remembers forever the last successful result, and use it whenever Contentful fails
and remove comments
7ff7245
to
63dca40
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Unit Test Results 1 files 7 suites 3m 0s ⏱️ Results for commit 63dca40. ♻️ This comment has been updated with latest results. |
to avoid docusaurus issue
Depends on #1640.⚠️ Please review it first
Description
Use memoization to remember forever the last successful invocation for each combination of arguments, and use its result whenever Contentful fails.
Context
Contentful failing during 1h on 2021/6/8 and 2021/6/9.
Approach taken / Explain the design
FallbackCachedClientApi does not use the memoization library used by CachedClientApi (memoizee) because this library does not allow directly accessing the cache.
To document / Usage example
The contentful plugin by default uses memoization to remember forever the last successful invocation for each combination of arguments, and use its result whenever Contentful fails. To disable this feature, use to
true
the new plugin option beloewTesting
The pull request...