Coverage for /builds/BuildGrid/buildgrid/buildgrid/server/actioncache/service.py: 100.00%

19 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-10-04 17:48 +0000

1# Copyright (C) 2018 Bloomberg LP 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# <http://www.apache.org/licenses/LICENSE-2.0> 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14 

15 

16from typing import cast 

17 

18import grpc 

19 

20from buildgrid._protos.build.bazel.remote.execution.v2.remote_execution_pb2 import DESCRIPTOR as RE_DESCRIPTOR 

21from buildgrid._protos.build.bazel.remote.execution.v2.remote_execution_pb2 import ( 

22 ActionResult, 

23 GetActionResultRequest, 

24 UpdateActionResultRequest, 

25) 

26from buildgrid._protos.build.bazel.remote.execution.v2.remote_execution_pb2_grpc import ( 

27 ActionCacheServicer, 

28 add_ActionCacheServicer_to_server, 

29) 

30from buildgrid.server.actioncache.instance import ActionCache 

31from buildgrid.server.decorators import rpc 

32from buildgrid.server.servicer import InstancedServicer 

33 

34 

35class ActionCacheService(ActionCacheServicer, InstancedServicer[ActionCache]): 

36 SERVICE_NAME = "ActionCache" 

37 REGISTER_METHOD = add_ActionCacheServicer_to_server 

38 FULL_NAME = RE_DESCRIPTOR.services_by_name[SERVICE_NAME].full_name 

39 

40 @rpc(instance_getter=lambda r: cast(str, r.instance_name)) 

41 def GetActionResult(self, request: GetActionResultRequest, context: grpc.ServicerContext) -> ActionResult: 

42 return self.current_instance.get_action_result(request.action_digest) 

43 

44 @rpc(instance_getter=lambda r: cast(str, r.instance_name)) 

45 def UpdateActionResult(self, request: UpdateActionResultRequest, context: grpc.ServicerContext) -> ActionResult: 

46 self.current_instance.update_action_result(request.action_digest, request.action_result) 

47 return request.action_result