diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-09-08 16:16:39 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-09-10 16:53:56 +0900 |
commit | 26ccc1ba12aae8d2f0bff2d1dc4abc39fe595381 (patch) | |
tree | 9b939175efa0a9aa166a9ec6fac436686237b482 /buildstream/_artifactcache/artifactcache.py | |
parent | 1f118ba4d9ff1a342ddcebf22be57205161209b8 (diff) | |
download | buildstream-26ccc1ba12aae8d2f0bff2d1dc4abc39fe595381.tar.gz |
_artifactcache: Making public methods public
The artifact cache provides the following public methods for
external callers, but was hiding them away as if they are private.
o ArtifactCache.add_artifact_size()
o ArtifactCache.set_cache_size()
Mark these properly public
Diffstat (limited to 'buildstream/_artifactcache/artifactcache.py')
-rw-r--r-- | buildstream/_artifactcache/artifactcache.py | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/buildstream/_artifactcache/artifactcache.py b/buildstream/_artifactcache/artifactcache.py index f162c7f08..b7a51793e 100644 --- a/buildstream/_artifactcache/artifactcache.py +++ b/buildstream/_artifactcache/artifactcache.py @@ -294,6 +294,38 @@ class ArtifactCache(): return self.estimated_size + # add_artifact_size() + # + # Adds the reported size of a newly cached artifact to the + # overall ArtifactCache.estimated_size. + # + # Args: + # artifact_size (int): The size to add. + # + def add_artifact_size(self, artifact_size): + if not self.estimated_size: + self.estimated_size = self.calculate_cache_size() + + self.estimated_size += artifact_size + self._write_cache_size(self.estimated_size) + + # set_cache_size() + # + # Forcefully set the overall cache size. + # + # This is used to update the size in the main process after + # having calculated in a cleanup or a cache size calculation job. + # + # Args: + # cache_size (int): The size to set. + # + def set_cache_size(self, cache_size): + self.estimated_size = cache_size + + # set_cache_size is called in cleanup, where it may set the cache to None + if self.estimated_size is not None: + self._write_cache_size(self.estimated_size) + ################################################ # Abstract methods for subclasses to implement # ################################################ @@ -535,35 +567,6 @@ class ArtifactCache(): with self.context.timed_activity("Initializing remote caches", silent_nested=True): self.initialize_remotes(on_failure=remote_failed) - # _add_artifact_size() - # - # Since we cannot keep track of the cache size between threads, - # this method will be called by the main process every time a - # process that added something to the cache finishes. - # - # This will then add the reported size to - # ArtifactCache.estimated_size. - # - def _add_artifact_size(self, artifact_size): - if not self.estimated_size: - self.estimated_size = self.calculate_cache_size() - - self.estimated_size += artifact_size - self._write_cache_size(self.estimated_size) - - # _set_cache_size() - # - # Similarly to the above method, when we calculate the actual size - # in a child thread, we can't update it. We instead pass the value - # back to the main thread and update it there. - # - def _set_cache_size(self, cache_size): - self.estimated_size = cache_size - - # set_cache_size is called in cleanup, where it may set the cache to None - if self.estimated_size is not None: - self._write_cache_size(self.estimated_size) - # _write_cache_size() # # Writes the given size of the artifact to the cache's size file |