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
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()
def get(self, request): # receive a type value through URL action_type = request.GET.get('type') # create the logger logger = GatewayLogger() # forward to gateway server when requested to a different server if THIS_SYSTEM != 'gateway': logger.set_log( action_type, 'P', 'requested task server not gateway, forwarding request to gateway server' ) task_sender = TaskSender(action_type) task_sender = task_sender.send_task(action_type) return JsonResponse({'status': 'FORWARDED'}, json_dumps_params={'ensure_ascii': True}) else: # check for action_type availability action_inst = GatewayActionOBJ(action_type) if action_inst.action_exists(): logger.set_log(action_type, 'P', 'store received action type') # initialize action class by passing in the action type retrieved from URL reducer_inst = GatewayReducer( action_inst) # pass in the action object to reducer reducer_status = reducer_inst.reduce() if reducer_status == True: logger.set_log(action_type, 'P', 'action successfully reduced') return JsonResponse( {'status': 'DONE'}, json_dumps_params={'ensure_ascii': True}) else: logger.set_log(action_type, 'F', 'action failed to reduce') return JsonResponse( {'status': 'FAIL'}, json_dumps_params={'ensure_ascii': True}) elif not action_inst.action_exists(): logger.set_log(action_type, 'F', 'no such action exists error') return JsonResponse( {'status': 'NO ACTION: {}'.format(action_type)}, json_dumps_params={'ensure_ascii': True})