try:
// Send an HTTP request for the tarball.
response = self._request("GET", remote_path)
if response is None:
returnNone
with temporary_file() as outfile:
total_bytes = 0// Read the data in a loop.for chunk in response.iter_content(self.READ_SIZE_BYTES):
outfile.write(chunk)
total_bytes += len(chunk)
outfile.close()
self.log.debug("Read %d bytes from artifact cache at %s" %
(total_bytes,self._url_string(remote_path)))
// Extract the tarfile.
artifact = TarballArtifact(self.artifact_root, outfile.name, self.compression)
artifact.extract()return artifact
except Exception as e:
self.log.warn("Error while reading from remote artifact cache: %s" % e)
return None
After Change
return self._request("HEAD", self._remote_path_for_key(cache_key)) is not None
def use_cached_files(self, cache_key):
if self._localcache.has(cache_key):
return self._localcache.use_cached_files(cache_key) remote_path = self._remote_path_for_key(cache_key)
try:
response = self._request("GET", remote_path)
if response is not None:
// Delegate storage and extraction to local cache
byte_iter = response.iter_content(self.READ_SIZE_BYTES)
return self._localcache.store_and_use_artifact(cache_key, byte_iter)
except Exception as e:
logger.warn("\nError while reading from remote artifact cache: {0}\n".format(e))
return False