-
Notifications
You must be signed in to change notification settings - Fork 11
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
Implement cache in Znoyder #165
Merged
Merged
Conversation
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
There will be additional Dumper introduced later, so lets keep them in the same place.
There are two utils submodules right now, so lets merge them together.
This commit introduces additional class that implements the persistent cache. It will be useful for reducing the actual queries to GitHub and OpenDev, as it turned out that there not many/often changes to list of upstream jobs.
It is all about inheriting from PyYAML base class and setting custom tag name and declaring this object as recognized by SafeLoader.
Later we can preserve the generated cache and stop querying GitHub hundreds of times.
It is possible now to specify it both with and without parentheses, e.g. @cache and @cache(). This opens a way to extend the functionality further with additional options passed.
This commit customizes the cache decorator so it is possible to specify what parameters will be used as cache keys ~ i.e. for function that we actually care about selected parameters that makes the actual difference we can consider only specified ones (by default all function parameters are considered). Additionally it is possible to produce a human-readable string instead of a calculated hash – this would make the generated cache file browsable for us in case we need that...
This commit adds sorting of ZuulJobs entries so when cached the produced output is always predictable and repeatable across multiple calls to generator, no matter who, where and when executes the code. This should allow us to include small incremental changes in cache file when regenerating the cache periodically for any upstream changes.
The existing code relied on absolute paths to files, which would result in generated cache to be specific for a given environment where the Znoyder is called. Using relative paths would make the calls universal and properly cacheable.
sdatko
requested review from
arxcruz,
dasm,
michaeltcoelho,
dsariel and
adrianfusco
January 24, 2024 15:50
adrianfusco
approved these changes
Jan 25, 2024
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 just can say this is wonderful +1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It turned out that the upstream jobs specification does not change that often like we initially assumed. However, with passing time and project growing, we begin to be overwhelmed by number of calls to GitHub and OpenDev for fetching the Zuul sources. This pull request introduces cache mechanism that would allow us to rely on a single local file providing us all the information about upstream jobs. Such file can be generated/updated periodically. It will be added to repository with a separate pull request.
Example of generated cache:
List of changes:
– Move NestedDumper to dedicated submodule
– Move utils to lib.utils submodule
– Add persistent cache
– Make ZuulJob dumpable with PyYAML
– Use cache in generator
– Make cache decorator callable in two ways
– Add selective cache option
– Make cache for generator predictable
– Use relative paths in generator