[Notes] [Git][BuildGrid/buildgrid][raoul/smarter-bot-calls] Bot: Reconnects and timeouts on the bot side



Title: GitLab

Raoul Hidalgo Charman pushed to branch raoul/smarter-bot-calls at BuildGrid / buildgrid

Commits:

3 changed files:

Changes:

  • buildgrid/bot/bot.py
    ... ... @@ -54,3 +54,5 @@ class Bot:
    54 54
             """
    
    55 55
             while True:
    
    56 56
                 self._bot_session.update_bot_session()
    
    57
    +            # If you get rid of this it breaks when actually executing commands
    
    58
    +            await asyncio.sleep(1)

  • buildgrid/bot/bot_interface.py
    ... ... @@ -21,7 +21,10 @@ Interface to grpc
    21 21
     """
    
    22 22
     
    
    23 23
     import logging
    
    24
    +from ..utils import timeout
    
    25
    +from ..settings import INTERVAL_BUFFER
    
    24 26
     
    
    27
    +import grpc
    
    25 28
     from buildgrid._protos.google.devtools.remoteworkers.v1test2 import bots_pb2, bots_pb2_grpc
    
    26 29
     
    
    27 30
     
    
    ... ... @@ -45,4 +48,15 @@ class BotInterface:
    45 48
             request = bots_pb2.UpdateBotSessionRequest(name=bot_session.name,
    
    46 49
                                                        bot_session=bot_session,
    
    47 50
                                                        update_mask=update_mask)
    
    48
    -        return self._stub.UpdateBotSession(request, timeout=self._interval)
    51
    +        try:
    
    52
    +            with timeout(30):
    
    53
    +                return self._stub.UpdateBotSession(
    
    54
    +                    request, timeout=self._interval + INTERVAL_BUFFER)
    
    55
    +        except grpc.StatusCode.DEADLINE_EXCEEDED:
    
    56
    +            self.logger.info("Server didn't respond")
    
    57
    +            return None
    
    58
    +        except TimeoutError:
    
    59
    +            self.logger.info("server didn't respond")
    
    60
    +        except Exception as e:
    
    61
    +            self.logger.info("Some error: {}".format(e))
    
    62
    +

  • buildgrid/utils.py
    ... ... @@ -16,6 +16,8 @@
    16 16
     from operator import attrgetter
    
    17 17
     import os
    
    18 18
     import socket
    
    19
    +from contextlib import contextmanager
    
    20
    +import signal
    
    19 21
     
    
    20 22
     from buildgrid.settings import HASH
    
    21 23
     from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2
    
    ... ... @@ -208,3 +210,15 @@ def output_directory_maker(directory_path, working_path, tree_digest):
    208 210
         output_directory.path = os.path.relpath(directory_path, start=working_path)
    
    209 211
     
    
    210 212
         return output_directory
    
    213
    +
    
    214
    +
    
    215
    +@contextmanager
    
    216
    +def timeout(seconds):
    
    217
    +    def raise_timeout(x, y):
    
    218
    +        raise TimeoutError
    
    219
    +    signal.signal(signal.SIGALRM, raise_timeout)
    
    220
    +    signal.alarm(seconds)
    
    221
    +    try:
    
    222
    +        yield
    
    223
    +    finally:
    
    224
    +        signal.alarm(0)



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]