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

19 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-06-11 15:37 +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 

16""" 

17Execution Controller 

18==================== 

19 

20An instance of the Execution controller. 

21 

22All this stuff you need to make the execution service work. 

23 

24Contains scheduler, execution instance, an interface to the bots 

25and an operations instance. 

26""" 

27from typing import Iterable, Optional 

28 

29from .._enums import ServiceName 

30from ..settings import DEFAULT_MAX_LIST_OPERATION_PAGE_SIZE 

31from .bots.instance import BotsInterface 

32from .execution.instance import ExecutionInstance 

33from .operations.instance import OperationsInstance 

34from .persistence.sql.impl import SQLDataStore 

35 

36 

37class ExecutionController: 

38 def __init__( 

39 self, 

40 scheduler: SQLDataStore, 

41 *, 

42 operation_stream_keepalive_timeout: Optional[int] = None, 

43 services: Iterable[str] = ServiceName.default_services(), 

44 max_list_operations_page_size: int = DEFAULT_MAX_LIST_OPERATION_PAGE_SIZE, 

45 job_assignment_interval: float = 1.0, 

46 priority_assignment_percentage: int = 100, 

47 ) -> None: 

48 self.execution_instance: Optional[ExecutionInstance] = None 

49 if ServiceName.EXECUTION.value in services: 

50 self.execution_instance = ExecutionInstance(scheduler, operation_stream_keepalive_timeout) 

51 

52 self.operations_instance: Optional[OperationsInstance] = None 

53 if ServiceName.OPERATIONS.value in services: 

54 self.operations_instance = OperationsInstance(scheduler, max_list_operations_page_size) 

55 

56 self.bots_interface: Optional[BotsInterface] = None 

57 if ServiceName.BOTS.value in services: 

58 self.bots_interface = BotsInterface( 

59 scheduler, 

60 job_assignment_interval=job_assignment_interval, 

61 priority_assignment_percentage=priority_assignment_percentage, 

62 )