def dr_custom_endpoint_verifier()

in source/tools/iot-dr-pubsub.py [0:0]


def dr_custom_endpoint_verifier(current_iot_endpoint, custom_endpoint):
    global MQTT_CONNECTION, T
    logger.info('running in dr-mode/custom_endpoint: current_iot_endpoint: %s MQTT_CONNECTION: %s T: %s',
        current_iot_endpoint, MQTT_CONNECTION, T)

    iot_endpoint = resolve_cname(custom_endpoint)
    logger.info('custom_endpoint: %s current_iot_endpoint: %s iot_endpoint: %s',
            custom_endpoint, current_iot_endpoint, iot_endpoint) 

    if current_iot_endpoint != iot_endpoint:
        logger.info('REGION FAILOVER detected: custom_endpoint: %s: %s -> %s',
                custom_endpoint, current_iot_endpoint, iot_endpoint)

        current_iot_endpoint = iot_endpoint
        logger.info('teminating current MQTT_CONNECTION')
        disconnect_future = MQTT_CONNECTION.disconnect()
        logger.info('disconnect_future result: %s', disconnect_future)
        disconnect_future.result()
        MQTT_CONNECTION = None
        logger.info('initiating new MQTT_CONNECTION to custom_endpoint: %s (%s)',
                custom_endpoint, iot_endpoint)
        connection_start(custom_endpoint)
        
    txt = resolve_txt(custom_endpoint)
    if 'primary' in txt and txt['primary'] == current_iot_endpoint.split('.')[2]:
        logger.info('PRIMARY region')
    elif 'secondary' in txt and txt['secondary'] == current_iot_endpoint.split('.')[2]:
        logger.info('SECONDARY region')
    else:
        logger.warning('unable to determine primary/secondary region')
    
    T = threading.Timer(60, dr_custom_endpoint_verifier, [current_iot_endpoint, custom_endpoint])
    T.start()