This is an automated email from the ASF dual-hosted git repository. tvb pushed a commit to branch ctolentino/test in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit e8f9efb272b66691969bb858f409d7618927b408 Author: ctolentino8 <[email protected]> AuthorDate: Thu Apr 9 15:47:53 2020 +0100 Create timed activity for waiting on buildbox-casd --- src/buildstream/_cas/cascache.py | 5 +-- src/buildstream/_cas/casdprocessmanager.py | 52 +++++++++++++++++++----------- src/buildstream/_context.py | 1 + 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py index 74912c4..795e04b 100644 --- a/src/buildstream/_cas/cascache.py +++ b/src/buildstream/_cas/cascache.py @@ -73,7 +73,8 @@ class CASCache: cache_quota=None, protect_session_blobs=True, log_level=CASLogLevel.WARNING, - log_directory=None + log_directory=None, + messenger=None, ): self.casdir = os.path.join(path, "cas") self.tmpdir = os.path.join(path, "tmp") @@ -91,7 +92,7 @@ class CASCache: path, log_dir, log_level, cache_quota, protect_session_blobs ) - self._casd_channel = self._casd_process_manager.create_channel() + self._casd_channel = self._casd_process_manager.create_channel(messenger) self._cache_usage_monitor = _CASCacheUsageMonitor(self._casd_channel) def __getstate__(self): diff --git a/src/buildstream/_cas/casdprocessmanager.py b/src/buildstream/_cas/casdprocessmanager.py index 5ba192d..f1c3826 100644 --- a/src/buildstream/_cas/casdprocessmanager.py +++ b/src/buildstream/_cas/casdprocessmanager.py @@ -223,12 +223,12 @@ class CASDProcessManager: # Return a CASDChannel, note that the actual connection is not necessarily # established until it is needed. # - def create_channel(self): - return CASDChannel(self._socket_path, self._connection_string, self._start_time, self.process.pid) + def create_channel(self, messenger=None): + return CASDChannel(self._socket_path, self._connection_string, self._start_time, self.process.pid, messenger) class CASDChannel: - def __init__(self, socket_path, connection_string, start_time, casd_pid): + def __init__(self, socket_path, connection_string, start_time, casd_pid, messenger): self._socket_path = socket_path self._connection_string = connection_string self._start_time = start_time @@ -237,25 +237,41 @@ class CASDChannel: self._casd_cas = None self._local_cas = None self._casd_pid = casd_pid + self._messenger = messenger + + def __getstate__(self): + state = self.__dict__.copy() + + # Messenger is not pickle-able + assert "_messenger" in state + state["_messenger"] = None + + return state def _establish_connection(self): assert self._casd_channel is None - while not os.path.exists(self._socket_path): - # casd is not ready yet, try again after a 10ms delay, - # but don't wait for more than specified timeout period - if time.time() > self._start_time + _CASD_TIMEOUT: - raise CASCacheError("Timed out waiting for buildbox-casd to become ready") - - # check that process is still alive - try: - proc = psutil.Process(self._casd_pid) - if not proc.is_running(): - raise CASCacheError(f"buildbox-casd process died before connection could be established") - except psutil.NoSuchProcess: - raise CASCacheError("buildbox-casd process died before connection could be established") - - time.sleep(0.01) + if self._messenger and not os.path.exists(self._socket_path): + cm = self._messenger.timed_activity("Waiting for buildbox-casd") + else: + cm = contextlib.suppress() + + with cm: + while not os.path.exists(self._socket_path): + # casd is not ready yet, try again after a 10ms delay, + # but don't wait for more than specified timeout period + if time.time() > self._start_time + _CASD_TIMEOUT: + raise CASCacheError("Timed out waiting for buildbox-casd to become ready") + + # check that process is still alive + try: + proc = psutil.Process(self._casd_pid) + if not proc.is_running(): + raise CASCacheError(f"buildbox-casd process died before connection could be established") + except psutil.NoSuchProcess: + raise CASCacheError("buildbox-casd process died before connection could be established") + + time.sleep(0.01) self._casd_channel = grpc.insecure_channel(self._connection_string) self._bytestream = bytestream_pb2_grpc.ByteStreamStub(self._casd_channel) diff --git a/src/buildstream/_context.py b/src/buildstream/_context.py index 090b3e0..38dbde6 100644 --- a/src/buildstream/_context.py +++ b/src/buildstream/_context.py @@ -539,6 +539,7 @@ class Context: cache_quota=self.config_cache_quota, log_level=log_level, log_directory=self.logdir, + messenger=self.messenger, ) return self._cascache
