Martin Blanchard pushed to branch mablanch/74-operation-cancelation at BuildGrid / buildgrid
Commits:
-
88d5f40d
by Martin Blanchard at 2018-10-11T20:31:26Z
-
f165fbb9
by Martin Blanchard at 2018-10-11T20:32:53Z
-
ce613386
by Martin Blanchard at 2018-10-11T20:33:55Z
3 changed files:
- buildgrid/_exceptions.py
- buildgrid/server/execution/instance.py
- buildgrid/server/execution/service.py
Changes:
... | ... | @@ -52,6 +52,11 @@ class BotError(BgdError): |
52 | 52 |
super().__init__(message, detail=detail, domain=ErrorDomain.BOT, reason=reason)
|
53 | 53 |
|
54 | 54 |
|
55 |
+class CancelledError(BgdError):
|
|
56 |
+ def __init__(self, message, detail=None, reason=None):
|
|
57 |
+ super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason)
|
|
58 |
+ |
|
59 |
+ |
|
55 | 60 |
class InvalidArgumentError(BgdError):
|
56 | 61 |
"""A bad argument was passed, such as a name which doesn't exist."""
|
57 | 62 |
def __init__(self, message, detail=None, reason=None):
|
... | ... | @@ -21,8 +21,9 @@ An instance of the Remote Execution Service. |
21 | 21 |
|
22 | 22 |
import logging
|
23 | 23 |
|
24 |
-from buildgrid._exceptions import FailedPreconditionError, InvalidArgumentError
|
|
25 |
-from buildgrid._protos.build.bazel.remote.execution.v2.remote_execution_pb2 import Action
|
|
24 |
+from buildgrid._exceptions import CancelledError, FailedPreconditionError, InvalidArgumentError
|
|
25 |
+from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2
|
|
26 |
+from buildgrid._protos.google.rpc import code_pb2
|
|
26 | 27 |
|
27 | 28 |
from ..job import Job
|
28 | 29 |
|
... | ... | @@ -43,7 +44,7 @@ class ExecutionInstance: |
43 | 44 |
this action.
|
44 | 45 |
"""
|
45 | 46 |
|
46 |
- action = self._storage.get_message(action_digest, Action)
|
|
47 |
+ action = self._storage.get_message(action_digest, remote_execution_pb2.Action)
|
|
47 | 48 |
|
48 | 49 |
if not action:
|
49 | 50 |
raise FailedPreconditionError("Could not get action from storage.")
|
... | ... | @@ -74,4 +75,11 @@ class ExecutionInstance: |
74 | 75 |
while not operation.done:
|
75 | 76 |
yield operation
|
76 | 77 |
operation = message_queue.get()
|
78 |
+ |
|
79 |
+ response = remote_execution_pb2.ExecuteResponse()
|
|
80 |
+ operation.response.Unpack(response)
|
|
81 |
+ |
|
82 |
+ if response.status.code == code_pb2.CANCELLED:
|
|
83 |
+ raise CancelledError(response.status.message)
|
|
84 |
+ |
|
77 | 85 |
yield operation
|
... | ... | @@ -26,7 +26,7 @@ from functools import partial |
26 | 26 |
|
27 | 27 |
import grpc
|
28 | 28 |
|
29 |
-from buildgrid._exceptions import FailedPreconditionError, InvalidArgumentError
|
|
29 |
+from buildgrid._exceptions import CancelledError, FailedPreconditionError, InvalidArgumentError
|
|
30 | 30 |
from buildgrid._protos.build.bazel.remote.execution.v2 import remote_execution_pb2_grpc
|
31 | 31 |
from buildgrid._protos.google.longrunning import operations_pb2
|
32 | 32 |
|
... | ... | @@ -67,6 +67,12 @@ class ExecutionService(remote_execution_pb2_grpc.ExecutionServicer): |
67 | 67 |
context.set_code(grpc.StatusCode.FAILED_PRECONDITION)
|
68 | 68 |
yield operations_pb2.Operation()
|
69 | 69 |
|
70 |
+ except CancelledError as e:
|
|
71 |
+ self.logger.error(e)
|
|
72 |
+ context.set_details(str(e))
|
|
73 |
+ context.set_code(grpc.StatusCode.CANCELLED)
|
|
74 |
+ yield operations_pb2.Operation()
|
|
75 |
+ |
|
70 | 76 |
def WaitExecution(self, request, context):
|
71 | 77 |
try:
|
72 | 78 |
names = request.name.split("/")
|