@inlineCallbacks
def route_notification(self, notification, uaid_data):
    "Route a notification to an internal node, and store it if the node\n        can't deliver immediately or is no longer a valid node\n        "
    node_id = uaid_data.get('node_id')
    uaid = uaid_data['uaid']
    router = self.db.router
    if node_id:
        result = None
        try:
            result = (yield self._send_notification(uaid, node_id, notification))
        except (ConnectError, ConnectionClosed, ResponseFailed, CancelledError, PotentialDataLoss) as exc:
            self.metrics.increment('updates.client.host_gone')
            (yield deferToThread(router.clear_node, uaid_data).addErrback(self._eat_db_err))
            if isinstance(exc, ConnectionRefusedError):
                self.log.debug('Could not route message: {exc}', exc=exc)
        if (result and (result.code == 200)):
            returnValue(self.delivered_response(notification))
    try:
        (yield self._save_notification(uaid_data, notification))
    except ClientError as e:
        log_exception = (e.response['Error']['Code'] != 'ProvisionedThroughputExceededException')
        raise RouterException('Error saving to database', status_code=503, response_body='Retry Request', log_exception=log_exception, errno=201)
    try:
        uaid_data = (yield deferToThread(router.get_uaid, uaid))
    except ClientError:
        returnValue(self.stored_response(notification))
    except ItemNotFound:
        self.metrics.increment('updates.client.deleted')
        raise RouterException('User was deleted', status_code=410, response_body='Invalid UAID', log_exception=False, errno=105)
    node_id = uaid_data.get('node_id')
    if (not node_id):
        returnValue(self.stored_response(notification))
    try:
        result = (yield self._send_notification_check(uaid, node_id))
    except (ConnectError, ConnectionClosed, ResponseFailed) as exc:
        self.metrics.increment('updates.client.host_gone')
        if isinstance(exc, ConnectionRefusedError):
            self.log.debug('Could not route message: {exc}', exc=exc)
        (yield deferToThread(router.clear_node, uaid_data).addErrback(self._eat_db_err))
        returnValue(self.stored_response(notification))
    if (result.code == 200):
        returnValue(self.delivered_response(notification))
    else:
        ret_val = self.stored_response(notification)
        returnValue(ret_val)
Route a notification to an internal node, and store it if the node
can't deliver immediately or is no longer a valid node
@inlineCallbacks
def route_notification(self, notification, uaid_data):
    "Route a notification to an internal node, and store it if the node\n        can't deliver immediately or is no longer a valid node\n        "
    node_id = uaid_data.get('node_id')
    uaid = uaid_data['uaid']
    router = self.db.router
    if node_id:
        result = None
        try:
            result = (yield self._send_notification(uaid, node_id, notification))
        except (ConnectError, ConnectionClosed, ResponseFailed, CancelledError, PotentialDataLoss) as exc:
            self.metrics.increment('updates.client.host_gone')
            (yield deferToThread(router.clear_node, uaid_data).addErrback(self._eat_db_err))
            if isinstance(exc, ConnectionRefusedError):
                self.log.debug('Could not route message: {exc}', exc=exc)
        if (result and (result.code == 200)):
            returnValue(self.delivered_response(notification))
    try:
        (yield self._save_notification(uaid_data, notification))
    except ClientError as e:
        log_exception = (e.response['Error']['Code'] != 'ProvisionedThroughputExceededException')
        raise RouterException('Error saving to database', status_code=503, response_body='Retry Request', log_exception=log_exception, errno=201)
    try:
        uaid_data = (yield deferToThread(router.get_uaid, uaid))
    except ClientError:
        returnValue(self.stored_response(notification))
    except ItemNotFound:
        self.metrics.increment('updates.client.deleted')
        raise RouterException('User was deleted', status_code=410, response_body='Invalid UAID', log_exception=False, errno=105)
    node_id = uaid_data.get('node_id')
    if (not node_id):
        returnValue(self.stored_response(notification))
    try:
        result = (yield self._send_notification_check(uaid, node_id))
    except (ConnectError, ConnectionClosed, ResponseFailed) as exc:
        self.metrics.increment('updates.client.host_gone')
        if isinstance(exc, ConnectionRefusedError):
            self.log.debug('Could not route message: {exc}', exc=exc)
        (yield deferToThread(router.clear_node, uaid_data).addErrback(self._eat_db_err))
        returnValue(self.stored_response(notification))
    if (result.code == 200):
        returnValue(self.delivered_response(notification))
    else:
        ret_val = self.stored_response(notification)
        returnValue(ret_val)