Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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""" 

27 

28 

29import logging 

30 

31from .scheduler import Scheduler 

32from .bots.instance import BotsInterface 

33from .execution.instance import ExecutionInstance 

34from .operations.instance import OperationsInstance 

35from .._enums import ServiceName 

36 

37 

38class ExecutionController: 

39 

40 def __init__(self, data_store, *, property_keys, storage=None, 

41 action_cache=None, action_browser_url=None, 

42 bot_session_keepalive_timeout=None, 

43 permissive_bot_session=None, 

44 services=ServiceName.default_services(), 

45 discard_unwatched_jobs=False, 

46 max_execution_timeout=None): 

47 self.__logger = logging.getLogger(__name__) 

48 

49 self.__logger = logging.getLogger(__name__) 

50 self._services = services 

51 

52 scheduler = Scheduler( 

53 data_store, 

54 action_cache=action_cache, 

55 action_browser_url=action_browser_url, 

56 max_execution_timeout=max_execution_timeout) 

57 

58 if ServiceName.EXECUTION.value in self._services: 

59 self._execution_instance = ExecutionInstance(scheduler, storage, property_keys, discard_unwatched_jobs) 

60 if ServiceName.BOTS.value in self._services: 

61 self._bots_interface = BotsInterface( 

62 data_store, action_cache=action_cache, 

63 bot_session_keepalive_timeout=bot_session_keepalive_timeout, 

64 permissive_bot_session=permissive_bot_session) 

65 if ServiceName.OPERATIONS.value in self._services: 

66 self._operations_instance = OperationsInstance(scheduler) 

67 

68 def register_instance_with_server(self, instance_name, server): 

69 if ServiceName.EXECUTION.value in self._services: 

70 self._execution_instance.register_instance_with_server(instance_name, server) 

71 if ServiceName.BOTS.value in self._services: 

72 self._bots_interface.register_instance_with_server(instance_name, server) 

73 if ServiceName.OPERATIONS.value in self._services: 

74 self._operations_instance.register_instance_with_server(instance_name, server) 

75 

76 @property 

77 def execution_instance(self): 

78 try: 

79 return self._execution_instance 

80 except AttributeError: 

81 return None 

82 

83 @property 

84 def bots_interface(self): 

85 try: 

86 return self._bots_interface 

87 except AttributeError: 

88 return None 

89 

90 @property 

91 def operations_instance(self): 

92 try: 

93 return self._operations_instance 

94 except AttributeError: 

95 return None