def dr_endpoint_verifier()

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


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

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

    if current_iot_endpoint != iot_endpoint:
        logger.info('REGION FAILOVER detected: %s -> %s',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 iot_endpoint: %s', iot_endpoint)
        connection_start(iot_endpoint)
        
    txt = resolve_txt(cname)
    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 - no TXT entry')
    
    T = threading.Timer(60, dr_endpoint_verifier, [current_iot_endpoint, cname])
    T.start()