コード例 #1
0
def delete_physical_del_channel_id(data):
    """
    accoding the id of data, to delete info in mongo, udpate the redis info
    step:
    first: get data from mongo
    second: delete data in mongo
    third: update data in redis
    :param data:
    :return:
    """
    id = data.get('id', '')

    try:
        result = q_db.physical_del_channel.find_one({"_id": ObjectId(id)})
        logger.debug('result:%s' % result)
    except Exception:
        logger.debug("delete_rewrite_prefix_id error, id:%s, exception:%s" %
                     (id, e))
        return json.dumsp({
            "msg":
            'error',
            'result':
            'get data from mongo error, exception:%s' % e
        })
    try:
        # delete data from mongo, according the id
        db.physical_del_channel.remove({"_id": ObjectId(id)})
        # operation_record_into_mongo(data.get('user_email'), 'channel_redirection', 'delete', result)
    except Exception:
        logger.debug(
            "delete_rewrite_prefix_id error, delete data error, id:%s, exception:%s"
            % (id, e))
        return json.dumsp({
            "msg":
            'error',
            'result':
            'del data from mongo error, exception:%s' % e
        })
    try:

        physical_del_channel = result.get("physical_del_channel", '')

        REWRITE_CACHE.delete('physical_del_channel_' + physical_del_channel)

    except Exception:
        logger.debug(
            "delete_rewrite_prefix_id error, delete redis error, id:%s, exception:%s"
            % (id, e))
        return json.dumps({
            "msg":
            'error',
            'result':
            'del data from redis error, exception:%s' % e
        })
    return json.dumps({
        'msg': 'ok',
        'result': 'delete_rewrite_prefix_id, success!'
    })
コード例 #2
0
def delete_physical_del_channel_id(data):
    """
    accoding the id of data, to delete info in mongo, udpate the redis info
    step:
    first: get data from mongo
    second: delete data in mongo
    third: update data in redis
    :param data:
    :return:
    """
    id = data.get('id', '')

    try:
        result = q_db.physical_del_channel.find_one({"_id": ObjectId(id)})
        logger.debug('result:%s' % result)
    except Exception, e:
        logger.debug("delete_rewrite_prefix_id error, id:%s, exception:%s" % (id, e))
        return json.dumsp({"msg": 'error', 'result': 'get data from mongo error, exception:%s' % e})
コード例 #3
0
            'error',
            'result':
            'get data from mongo error, exception:%s' % e
        })
    try:
        # delete data from mongo, according the id
        db.rewrite_new.remove({"_id": ObjectId(id)})
        operation_record_into_mongo(data.get('user_email'),
                                    'channel_redirection', 'delete', result)
    except Exception, e:
        logger.debug(
            "delete_rewrite_id error, delete data error, id:%s, exception:%s" %
            (id, e))
        return json.dumsp({
            "msg":
            'error',
            'result':
            'del data from mongo error, exception:%s' % e
        })
    try:
        # the data of channel_list from mongo
        channel_list = result.get("channel_list", '')
        logger.debug("channel_list:%s" % channel_list)

        length_c = len(channel_list)
        # handle the lengh of channel_list bigger than 2 or eq 2
        if channel_list and length_c >= 2:
            for i in range(length_c):
                channel = channel_list[i]
                channel_list.pop(i)
                channels_redis = REWRITE_CACHE.get(channel)
                logger.debug("channel:%s, channels_redis:%s" %
コード例 #4
0
def delete_rewrite_prefix_id(data):
    """
    accoding the id of data, to delete info in mongo, udpate the redis info
    step:
    first: get data from mongo
    second: delete data in mongo
    third: update data in redis
    :param data:
    :return:
    """
    id = data.get('id', '')

    try:
        result = q_db.rewrite_prefix.find_one({"_id": ObjectId(id)})
        logger.debug('result:%s' % result)
    except Exception:
        logger.debug("delete_rewrite_prefix_id error, id:%s, exception:%s" %
                     (id, e))
        return json.dumsp({
            "msg":
            'error',
            'result':
            'get data from mongo error, exception:%s' % e
        })
    try:
        # delete data from mongo, according the id
        db.rewrite_prefix.remove({"_id": ObjectId(id)})
        # operation_record_into_mongo(data.get('user_email'), 'channel_redirection', 'delete', result)
    except Exception:
        logger.debug(
            "delete_rewrite_prefix_id error, delete data error, id:%s, exception:%s"
            % (id, e))
        return json.dumsp({
            "msg":
            'error',
            'result':
            'del data from mongo error, exception:%s' % e
        })
    try:
        # the data of channel_list from mongo
        username = result.get('username', '')
        channel_original = result.get("channel_original", '')
        channels_after = result.get('channels_after', '')

        for i in range(len(channels_after)):
            REWRITE_CACHE.srem('prefix_' + channel_original, channels_after[i])
        REWRITE_CACHE.srem('prefix_username_' + username, channel_original)
        value_username = REWRITE_CACHE.hincrby('url_prefix_list_users',
                                               username, -1)
        # if value_username <= 0:
        #     REWRITE_CACHE.hdel('url_prefix_list_users', username)

    except Exception:
        logger.debug(
            "delete_rewrite_prefix_id error, delete redis error, id:%s, exception:%s"
            % (id, e))
        return json.dumps({
            "msg":
            'error',
            'result':
            'del data from redis error, exception:%s' % e
        })
    return json.dumps({
        'msg': 'ok',
        'result': 'delete_rewrite_prefix_id, success!'
    })
コード例 #5
0
def delete_rewrite_id(data):
    """
    accoding the id of data, to delete info in mongo, udpate the redis info
    step:
    first: get data from mongo
    second: delete data in mongo
    third: update data in redis
    :param data:
    :return:
    """
    id = data.get('id', '')

    try:
        result = q_db.rewrite_new.find_one({"_id": ObjectId(id)})
        logger.debug('result:%s' % result)
    except Exception:
        logger.debug("delete_rewrite_id error, id:%s, exception:%s" % (id, e))
        return json.dumsp({
            "msg":
            'error',
            'result':
            'get data from mongo error, exception:%s' % e
        })
    try:
        # delete data from mongo, according the id
        db.rewrite_new.remove({"_id": ObjectId(id)})
        operation_record_into_mongo(data.get('user_email'),
                                    'channel_redirection', 'delete', result)
    except Exception:
        logger.debug(
            "delete_rewrite_id error, delete data error, id:%s, exception:%s" %
            (id, e))
        return json.dumsp({
            "msg":
            'error',
            'result':
            'del data from mongo error, exception:%s' % e
        })
    try:
        # the data of channel_list from mongo
        channel_list = result.get("channel_list", '')
        logger.debug("channel_list:%s" % channel_list)

        length_c = len(channel_list)
        # handle the lengh of channel_list bigger than 2 or eq 2
        if channel_list and length_c >= 2:
            for i in range(length_c):
                channel = channel_list[i]
                channel_list.pop(i)
                channels_redis = REWRITE_CACHE.get(channel)
                logger.debug("channel:%s, channels_redis:%s" %
                             (channel, channels_redis))
                if channels_redis:
                    channels = channels_redis.split(',')
                    for chann in channel_list:
                        # delete the appropriate channel which is in mongo
                        channels.remove(chann)
                    if len(channels) >= 1:
                        REWRITE_CACHE.set(channel, (',').join(channels))
                    else:
                        # the length of value is 0, the delete the channel in redis
                        REWRITE_CACHE.delete(channel)
                # to restore the original appearance
                channel_list.insert(i, channel)
    except Exception:
        logger.debug(
            "delete_rewrite_id error, delete redis error, id:%s, exception:%s"
            % (id, e))
        return json.dumps({
            "msg":
            'error',
            'result':
            'del data from redis error, exception:%s' % e
        })
    return json.dumps({'msg': 'ok', 'result': 'delete_rewrite_id, success!'})