def record_api_history(self, request): request_info = request.META user_obj = request.user remote_addr = request_info.get('REMOTE_ADDR', None) method = request_info.get('REQUEST_METHOD', None) path_info = request_info.get('PATH_INFO', None) query_string = request_info.get('QUERY_STRING', None) # 验证用户有没有功资源平台的权限 if not user_obj.is_superuser and 'rs_public' in path_info: raise RsError('用户权限禁止访问资源数据') # 获得post data post_data = request.data if len(post_data) > 0: post_data = json.dumps(post_data) else: post_data = None data = { 'create_time': get_current_timestamp(), 'update_time': get_current_timestamp(), 'user_id': user_obj.id, 'remote_addr': remote_addr, 'method': method, 'app_url': "/".join(path_info.split("/")[2:4]), 'path_info': path_info, 'query_string': query_string, 'post_data': post_data, } save_api_record_task.delay(data)
def update(self, instance, validated_data): instance.appid = validated_data.get('appid', instance.appid) instance.response_time = validated_data.get('response_time', instance.response_time) instance.update_time = get_current_timestamp() instance.save() return instance
def insert_normal_cat_job(): """ 定时导入前一天的正常数据 :return: """ logger.info('insert_normal_cat_job ....') dt_time = datetime.datetime.now() + datetime.timedelta(days=-1) start_time = convert_datetime_to_timestamp(dt_time) end_time = get_current_timestamp() data = get_cache_cat_data(start_time, end_time) insert_normal_cat_data.delay(data)