summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2019-09-19 11:53:46 +0200
committerJürg Billeter <j@bitron.ch>2019-09-19 14:20:21 +0200
commit08de3b1a405bda2c0de9174d7f82a619dd96b775 (patch)
tree6c40421f3542b9e726fad144f8e889299dc88abd
parentd06fd33a9ab09e64446c7c90780f001a26e86d8e (diff)
downloadbuildstream-08de3b1a405bda2c0de9174d7f82a619dd96b775.tar.gz
_artifactcache.py: Create ArtifactServiceStub in _configure_protocols()
There is no need to create a new stub for every request. This also matches what SourceRemote does.
-rw-r--r--src/buildstream/_artifactcache.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/buildstream/_artifactcache.py b/src/buildstream/_artifactcache.py
index 0e2eb1091..2f2fdc8cb 100644
--- a/src/buildstream/_artifactcache.py
+++ b/src/buildstream/_artifactcache.py
@@ -37,6 +37,11 @@ from . import utils
# artifact remotes.
#
class ArtifactRemote(BaseRemote):
+
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.artifact_service = None
+
# _configure_protocols():
#
# Configure the protocols used by this remote as part of the
@@ -44,7 +49,6 @@ class ArtifactRemote(BaseRemote):
# Remote.init(), and is expected to fail when called by itself.
#
def _configure_protocols(self):
- # Add artifact stub
capabilities_service = buildstream_pb2_grpc.CapabilitiesStub(self.channel)
# Check whether the server supports newer proto based artifact.
@@ -67,6 +71,9 @@ class ArtifactRemote(BaseRemote):
raise ArtifactError(
"Configured remote does not support artifact service")
+ # Set up artifact stub
+ self.artifact_service = artifact_pb2_grpc.ArtifactServiceStub(self.channel)
+
# get_artifact():
#
# Get an artifact proto for a given cache key from the remote.
@@ -86,8 +93,7 @@ class ArtifactRemote(BaseRemote):
artifact_request = artifact_pb2.GetArtifactRequest()
artifact_request.cache_key = cache_key
- artifact_service = artifact_pb2_grpc.ArtifactServiceStub(self.channel)
- return artifact_service.GetArtifact(artifact_request)
+ return self.artifact_service.GetArtifact(artifact_request)
# update_artifact():
#
@@ -106,8 +112,7 @@ class ArtifactRemote(BaseRemote):
update_request.cache_key = cache_key
update_request.artifact.CopyFrom(artifact)
- artifact_service = artifact_pb2_grpc.ArtifactServiceStub(self.channel)
- artifact_service.UpdateArtifact(update_request)
+ self.artifact_service.UpdateArtifact(update_request)
# An ArtifactCache manages artifacts.
@@ -707,8 +712,7 @@ class ArtifactCache(BaseCache):
request = artifact_pb2.GetArtifactRequest()
request.cache_key = ref
try:
- artifact_service = artifact_pb2_grpc.ArtifactServiceStub(remote.channel)
- artifact_service.GetArtifact(request)
+ remote.artifact_service.GetArtifact(request)
except grpc.RpcError as e:
if e.code() != grpc.StatusCode.NOT_FOUND:
raise ArtifactError("Error when querying: {}".format(e.details()))