def run_alerters_manager(manager: AlertersManager) -> None: while True: try: manager.start() except (pika.exceptions.AMQPConnectionError, pika.exceptions.AMQPChannelError): # Error would have already been logged by RabbitMQ logger. # Since we have to re-initialise just break the loop. log_and_print(get_stopped_message(manager), manager.logger) except Exception: # Close the connection with RabbitMQ if we have an unexpected # exception, and start again manager.disconnect_from_rabbit() log_and_print(get_stopped_message(manager), manager.logger) log_and_print( "Restarting {} in {} seconds.".format(manager, RESTART_SLEEPING_PERIOD), manager.logger) time.sleep(RESTART_SLEEPING_PERIOD)
def start_monitor(monitor: Monitor) -> None: while True: try: log_and_print("{} started.".format(monitor), monitor.logger) monitor.start() except (pika.exceptions.AMQPConnectionError, pika.exceptions.AMQPChannelError): # Error would have already been logged by RabbitMQ logger. log_and_print(get_stopped_message(monitor), monitor.logger) except Exception: # Close the connection with RabbitMQ if we have an unexpected # exception, and start again monitor.disconnect_from_rabbit() log_and_print(get_stopped_message(monitor), monitor.logger) log_and_print( "Restarting {} in {} seconds.".format(monitor, RESTART_SLEEPING_PERIOD), monitor.logger) time.sleep(RESTART_SLEEPING_PERIOD)
def start_health_checker_component(component: HealthCheckerComponentType) \ -> None: while True: try: log_and_print("{} started.".format(component), component.logger) component.start() except (pika.exceptions.AMQPConnectionError, pika.exceptions.AMQPChannelError): # Error would have already been logged by RabbitMQ logger. log_and_print(get_stopped_message(component), component.logger) except Exception: # Close the connection with RabbitMQ if we have an unexpected # exception, and start again component.disconnect_from_rabbit() log_and_print(get_stopped_message(component), component.logger) log_and_print( "Restarting {} in {} seconds.".format(component, RESTART_SLEEPING_PERIOD), component.logger) time.sleep(RESTART_SLEEPING_PERIOD)
def run_config_manager() -> None: config_manager, config_manager_logger = _initialise_config_manager() while True: try: config_manager.start() except (pika.exceptions.AMQPConnectionError, pika.exceptions.AMQPChannelError): # Error would have already been logged by RabbitMQ logger. # Since we have to re-initialise just break the loop. log_and_print(get_stopped_message(config_manager), config_manager_logger) except Exception: config_manager.disconnect_from_rabbit() log_and_print(get_stopped_message(config_manager), config_manager_logger) log_and_print( "Restarting {} in {} seconds.".format(config_manager, RESTART_SLEEPING_PERIOD), config_manager_logger) time.sleep(RESTART_SLEEPING_PERIOD)
def run_health_checker_manager() -> None: health_checker_manager = _initialise_health_checker_manager() while True: try: log_and_print("{} started.".format(health_checker_manager), health_checker_manager.logger) health_checker_manager.start() except Exception as e: health_checker_manager.logger.exception(e) log_and_print(get_stopped_message(health_checker_manager), health_checker_manager.logger) log_and_print("Restarting {} in {} seconds.".format( health_checker_manager, RESTART_SLEEPING_PERIOD), health_checker_manager.logger) time.sleep(RESTART_SLEEPING_PERIOD)