Island: Extract event topic to a variable in all Island event handler subscribe functions

This commit is contained in:
Shreya Malviya 2022-09-21 16:26:04 +05:30
parent 5a96d5b570
commit 1f96ab5ea9
1 changed files with 14 additions and 17 deletions

View File

@ -28,25 +28,23 @@ def setup_island_event_handlers(container: DIContainer):
def _subscribe_reset_agent_configuration_events( def _subscribe_reset_agent_configuration_events(
island_event_queue: IIslandEventQueue, container: DIContainer island_event_queue: IIslandEventQueue, container: DIContainer
): ):
island_event_queue.subscribe( topic = IslandEventTopic.RESET_AGENT_CONFIGURATION
IslandEventTopic.RESET_AGENT_CONFIGURATION, container.resolve(reset_agent_configuration)
) island_event_queue.subscribe(topic, container.resolve(reset_agent_configuration))
def _subscribe_clear_simulation_data_events( def _subscribe_clear_simulation_data_events(
island_event_queue: IIslandEventQueue, container: DIContainer island_event_queue: IIslandEventQueue, container: DIContainer
): ):
topic = IslandEventTopic.CLEAR_SIMULATION_DATA
legacy_database_reset = partial(Database.reset_db, reset_config=False) legacy_database_reset = partial(Database.reset_db, reset_config=False)
island_event_queue.subscribe(IslandEventTopic.CLEAR_SIMULATION_DATA, legacy_database_reset) island_event_queue.subscribe(topic, legacy_database_reset)
credentials_repository = container.resolve(ICredentialsRepository) credentials_repository = container.resolve(ICredentialsRepository)
island_event_queue.subscribe( island_event_queue.subscribe(topic, credentials_repository.remove_stolen_credentials)
IslandEventTopic.CLEAR_SIMULATION_DATA, credentials_repository.remove_stolen_credentials
)
island_event_queue.subscribe( island_event_queue.subscribe(topic, container.resolve(reset_machine_repository))
IslandEventTopic.CLEAR_SIMULATION_DATA, container.resolve(reset_machine_repository)
)
for i_repository in [ for i_repository in [
INodeRepository, INodeRepository,
@ -54,15 +52,14 @@ def _subscribe_clear_simulation_data_events(
IAgentRepository, IAgentRepository,
]: ]:
repository = container.resolve(i_repository) repository = container.resolve(i_repository)
island_event_queue.subscribe(IslandEventTopic.CLEAR_SIMULATION_DATA, repository.reset) island_event_queue.subscribe(topic, repository.reset)
def _subscribe_set_island_mode_events( def _subscribe_set_island_mode_events(
island_event_queue: IIslandEventQueue, container: DIContainer island_event_queue: IIslandEventQueue, container: DIContainer
): ):
island_event_queue.subscribe( topic = IslandEventTopic.SET_ISLAND_MODE
IslandEventTopic.SET_ISLAND_MODE, container.resolve(set_agent_configuration_per_island_mode)
) island_event_queue.subscribe(topic, container.resolve(set_agent_configuration_per_island_mode))
island_event_queue.subscribe(
IslandEventTopic.SET_ISLAND_MODE, container.resolve(set_simulation_mode) island_event_queue.subscribe(topic, container.resolve(set_simulation_mode))
)