Example #1
0
def restart_test():
    task_name = 'RESTART_TEST'
    logger = GatewayLogger()
    task_sender = TaskSender(task_name)

    logger.set_log(task_name, 'P',
                   'gobble server received task: {}'.format(task_name))

    # delete all TEST action related gateway logs
    GatewayState.objects.filter(task_name='TEST').delete()
    test_logs_num = GatewayState.objects.filter(task_name='TEST').count()
    if test_logs_num == 0:
        logger.set_log(task_name, 'P', 'deleted all TEST action related logs')

    # test redis can delete data
    r = RedisClient()
    res = r.del_key('TEST')
    if res == 1:
        logger.set_log(task_name, 'P', 'deleted key: {}'.format('TEST'))
    cache.delete('TEST2')
    logger.set_log(task_name, 'P', 'deleted key: {}'.format('TEST2'))
    # as a finishing touch retest TEST action by sending action
    task_sender.send_task('TEST')
    logger.set_log(task_name, 'P', 'COMPLETE')
    return True
Example #2
0
def mass_date_save(cache_key):
    try:  # always capture exceptions with Sentry
        task_name = 'MASS_DATE_SAVE'
        logger = GatewayLogger()
        task_sender = TaskSender(task_name)

        # log to gateway server
        logger.set_log(task_name, 'P',
                       'gobble server received task: {}'.format(task_name))
        r = RedisClient()
        res = r.get_list(cache_key)
        date_list = []
        for date in res:
            date_inst = Date(date=date)
            date_list.append(date_inst)
        Date.objects.bulk_create(date_list)
        logger.set_log(task_name, 'P', 'saved mass_date data to Django DB')

        # delete duplicates if existent
        unique_dates = Date.objects.distinct('date')
        deleted = Date.objects.exclude(pk__in=unique_dates).delete()
        if deleted != 0:
            logger.set_log(task_name, 'P', 'deleted duplicate dates in DB')

        # delete cache key after done to prevent duplicates in cache server
        cache_deleted = r.del_key(cache_key)
        if cache_deleted:
            logger.set_log(task_name, 'P', 'deleted cache key in cache server')
        else:
            logger.set_log(task_name, 'F', 'failed to delete cache key')

        return True
    except:
        client.captureException()
Example #3
0
def mass_sd_save(**params):
    gobble_mass_sd_save = params['gobble_mass_sd_save']
    data_date_cache_key = params['mass_sd_date']
    data_cache_key = params['data_cache_key']
    state_cache_key = params['state_cache_key']

    r = RedisClient()

    if r.key_exists(data_date_cache_key):
        data_date = r.get_key(data_date_cache_key)
Example #4
0
def get_wonseok_test():
    try:
        task_name = 'GET_WONSEOK_TEST'
        logger = GatewayLogger()
        task_sender = TaskSender(task_name)

        logger.set_log(task_name, 'P',
                       'gobble server received task: {}'.format(task_name))
        r = RedisClient()
        r.set_key('wonseok_test_from_local', 'this is a test value')
        logger.set_log(task_name, 'P', 'key value set to cache')
        task_sender.send_task('SAVE_WONSEOK_TEST')
        return True
    except:
        client.captureException()
Example #5
0
def save_wonseok_test():
    try:
        task_name = 'SAVE_WONSEOK_TEST'
        logger = GatewayLogger()
        task_sender = TaskSender(task_name)

        logger.set_log(task_name, 'P',
                       'gobble server received task: {}'.format(task_name))
        r = RedisClient()
        value = r.get_key('wonseok_test_from_local')
        soul_log_data = SoulLog(log=value)
        soul_log_data.save()
        logger.set_log(task_name, 'P', 'key value saved to DB')
        return True
    except:
        client.captureException()
Example #6
0
def test():
    task_name = 'TEST'
    logger = GatewayLogger()
    logger.set_log(task_name, 'P',
                   'gobble server received task: {}'.format(task_name))
    # test redis can set/get data
    r = RedisClient()
    r.set_key('TEST', 'testing gateway API data flow')
    res = r.get_key('TEST')
    logger.set_log(
        task_name, 'P',
        'TEST 1: cache has key: {0}, with value: {1}'.format('TEST', res))
    cache.set('TEST2', 'testing Django cache set/get')
    res2 = cache.get('TEST2')
    logger.set_log(
        task_name, 'P',
        'TEST 2: django cache has key: {0}, with value: {1}'.format(
            'TEST2', res2))
    logger.set_log(task_name, 'P', 'COMPLETE')
    return True
def testCache():
    print('Test cache can create instance')
    r = RedisClient()
    print(r.redis_client)
    print('==========')

    print('Test cache can set key')
    res = r.set_key('pythontest', 'testing set key with python client')
    print(res)
    print('==========')

    print('Test cache can get key')
    res = r.get_key('pythontest')
    print(res)
    print('==========')

    print('Test cache can check for key existence')
    res = r.key_exists('pythontest')
    print(res)
    print('==========')

    print('Test cache can delete key')
    res = r.del_key('pythontest')
    print(res)
    print('==========')

    print('Test cache can set list')
    listdata = ['pythonlisttest', 1, 2, 3, 4, 5]
    if r.key_exists('pythonlisttest'):
        r.del_key('pythonlisttest')
    res = r.set_list(listdata)
    print(res)
    print('==========')

    print('Test cache can set list of string values')
    listdata2 = ['pythonlisttest2', 'a', 'b', 'c', 'd']
    if r.key_exists('pythonlisttest2'):
        r.del_key('pythonlisttest2')
    res = r.set_list(listdata2)
    print(res)
    print('==========')

    print('Test cache can get list')
    res = r.get_list('pythonlisttest', 'int')
    print(res)
    print('==========')

    print('Test cache can get list of string values')
    res = r.get_list('pythonlisttest2', 'str')
    print(res)
    print('==========')

    print('Test cache can set json')
    jsondata = {'key1': 1, 'key2': 2, 'keykey': {'keykey1': 1, 'keykey2': 2}}
    if r.key_exists('pythonjsontest'):
        r.del_key('pythonjsontest')
    res = r.set_json('pythonjsontest', jsondata)
    print(res)
    print('==========')

    print('Test cache can get json')
    res = r.get_json('pythonjsontest')
    print(res)
    print(res['key1'])
    print(res['keykey']['keykey1'])
    print('==========')

    print('Test cache can set pd dataframe')
    df = pd.DataFrame([1, 2, 3, 4, 5])
    if r.key_exists('dftest'):
        r.del_key('dftest')
    res = r.set_df('dftest', df)
    print(res)
    print('==========')

    print('Test cache can get pd dataframe')
    res = r.get_df('dftest')
    print(res)
    print(res[0])
    print('==========')