You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by gi...@apache.org on 2020/12/29 13:09:17 UTC
[buildstream] 14/16: casdprocessmanager: extract
_UnixSocketConnection
This is an automated email from the ASF dual-hosted git repository.
github-bot pushed a commit to branch aevri/win32_receive_signals
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 7b51e4a2a3294adf62e37c5774a587282500b5a5
Author: Angelos Evripiotis <je...@bloomberg.net>
AuthorDate: Fri Oct 11 14:02:11 2019 +0100
casdprocessmanager: extract _UnixSocketConnection
Prepare for different kinds of connection to buildbox-casd by creating
an abstraction over connection type.
---
src/buildstream/_cas/casdprocessmanager.py | 41 +++++++++++++++++++++++++-----
1 file changed, 34 insertions(+), 7 deletions(-)
diff --git a/src/buildstream/_cas/casdprocessmanager.py b/src/buildstream/_cas/casdprocessmanager.py
index 2f28910..e83e128 100644
--- a/src/buildstream/_cas/casdprocessmanager.py
+++ b/src/buildstream/_cas/casdprocessmanager.py
@@ -27,10 +27,15 @@ import time
from .. import _signals, utils
from .._message import Message, MessageType
+from ..types import FastEnum
_CASD_MAX_LOGFILES = 10
+class ConnectionType(FastEnum):
+ UNIX_SOCKET = 0
+
+
# CASDProcessManager
#
# This manages the subprocess that runs buildbox-casd.
@@ -41,17 +46,23 @@ _CASD_MAX_LOGFILES = 10
# log_level (LogLevel): Log level to give to buildbox-casd for logging
# cache_quota (int): User configured cache quota
# protect_session_blobs (bool): Disable expiry for blobs used in the current session
+# connection_type (ConnectionType): How to connect to the cas daemon
#
class CASDProcessManager:
- def __init__(self, path, log_dir, log_level, cache_quota, protect_session_blobs):
+ def __init__(
+ self,
+ path,
+ log_dir,
+ log_level,
+ cache_quota,
+ protect_session_blobs,
+ connection_type=ConnectionType.UNIX_SOCKET,
+ ):
self._log_dir = log_dir
- # Place socket in global/user temporary directory to avoid hitting
- # the socket path length limit.
- self._socket_tempdir = tempfile.mkdtemp(prefix='buildstream')
- socket_path = os.path.join(self._socket_tempdir, 'casd.sock')
- self.connection_string = "unix:" + socket_path
+ assert connection_type == ConnectionType.UNIX_SOCKET
+ self._connection = _UnixSocketConnection()
casd_args = [utils.get_host_tool('buildbox-casd')]
casd_args.append('--bind=' + self.connection_string)
@@ -79,6 +90,10 @@ class CASDProcessManager:
self._failure_callback = None
self._watcher = None
+ @property
+ def connection_string(self):
+ return self._connection.connection_string
+
# _rotate_and_get_next_logfile()
#
# Get the logfile to use for casd
@@ -108,7 +123,7 @@ class CASDProcessManager:
def release_resources(self, messenger=None):
self._terminate(messenger)
self._process = None
- shutil.rmtree(self._socket_tempdir)
+ self._connection.release_resouces()
# _terminate()
#
@@ -216,3 +231,15 @@ class CASDProcessManager:
assert self._failure_callback is not None
self._process.returncode = returncode
self._failure_callback()
+
+
+class _UnixSocketConnection:
+ def __init__(self):
+ # Place socket in global/user temporary directory to avoid hitting
+ # the socket path length limit.
+ self._socket_tempdir = tempfile.mkdtemp(prefix='buildstream')
+ socket_path = os.path.join(self._socket_tempdir, 'casd.sock')
+ self.connection_string = "unix:" + socket_path
+
+ def release_resouces(self):
+ shutil.rmtree(self._socket_tempdir)