Esempio n. 1
0
 def innerResourceInstanceMethod(*args,**kwargs) :
     resourceInstance = args[0]
     try :
         FlaskManager.validateArgs(args,requestClass,innerResourceInstanceMethod)
         methodReturn = resourceInstanceMethod(*args,**kwargs)
     except Exception as exception :
         FlaskManager.raiseAndPersistGlobalException(exception, resourceInstance, resourceInstanceMethod)
     return methodReturn
 def innerResourceInstanceMethod(*args, **kwargs):
     f'''(*args, {FlaskUtil.KW_HEADERS}={{}}, {FlaskUtil.KW_PARAMETERS}={{}}, **kwargs)'''
     resourceInstance = args[0]
     clientResponse = None
     completeResponse = None
     try :
         FlaskManager.validateKwargs(
             kwargs,
             resourceInstance,
             resourceInstanceMethod,
             requestHeaderClass,
             requestParamClass
         )
         FlaskManager.validateArgs(args, requestClass, resourceInstanceMethod)
         clientResponse = None
         httpClientEvent = getHttpClientEvent(resourceInstanceMethod, *args, **kwargs)
         if isinstance(httpClientEvent, ManualHttpClientEvent):
             completeResponse = httpClientEvent.completeResponse
         elif isinstance(httpClientEvent, HttpClientEvent):
             try :
                 clientResponse = HTTP_CLIENT_RESOLVERS_MAP.get(
                     httpClientEvent.verb,
                     raiseHttpClientEventNotFoundException
                 )(
                     resourceInstance,
                     *httpClientEvent.args,
                     **httpClientEvent.kwargs
                 )
             except Exception as exception:
                 raiseException(clientResponse, exception)
             raiseExceptionIfNeeded(clientResponse)
             completeResponse = getCompleteResponse(clientResponse, responseClass, produces)
             FlaskManager.validateCompleteResponse(responseClass, completeResponse)
         else:
             raise Exception('Unknown http client event')
     except Exception as exception:
         log.log(innerResourceInstanceMethod, 'Failure at client method execution', exception=exception, muteStackTrace=True)
         FlaskManager.raiseAndPersistGlobalException(exception, resourceInstance, resourceInstanceMethod, context=HttpDomain.CLIENT_CONTEXT)
     clientResponseStatus = completeResponse[-1]
     clientResponseHeaders = completeResponse[1]
     clientResponseBody = completeResponse[0] if ObjectHelper.isNotNone(completeResponse[0]) else {'message' : HttpStatus.map(clientResponseStatus).enumName}
     if resourceInstance.logResponse or logResponse :
         log.prettyJson(
             resourceInstanceMethod,
             '[CLIENT    ] Response',
             {
                 'headers': clientResponseHeaders,
                 'body': Serializer.getObjectAsDictionary(clientResponseBody),
                 'status': clientResponseStatus
             },
             condition = True,
             logLevel = log.INFO
         )
     if returnOnlyBody:
         return completeResponse[0]
     else:
         return completeResponse
Esempio n. 3
0
 def innerResourceInstanceMethod(*args, **kwargs):
     resourceInstanceName = methodClassName[:-len(
         FlaskManager.KW_SCHEDULER_RESOURCE)]
     resourceInstanceName = f'{resourceInstanceName[0].lower()}{resourceInstanceName[1:]}'
     args = FlaskManager.getArgumentInFrontOfArgs(
         args,
         ReflectionHelper.getAttributeOrMethod(
             apiInstance.resource.scheduler, resourceInstanceName))
     resourceInstance = args[0]
     muteLogs = resourceInstance.muteLogs or resourceMethod.muteLogs
     if resourceInstance.enabled and not resourceInstance.disabled and not resourceMethod.disabled:
         if not muteLogs:
             log.debug(
                 resourceMethod,
                 f'{resourceMethod.shedulerId} scheduler started with args={methodArgs} and kwargs={methodKwargs}'
             )
         methodReturn = None
         try:
             FlaskManager.validateArgs(args, requestClass,
                                       innerResourceInstanceMethod)
             methodReturn = resourceMethod(*args, **kwargs)
         except Exception as exception:
             if not muteLogs:
                 log.warning(
                     resourceMethod,
                     f'Not possible to run {resourceMethod.shedulerId} properly',
                     exception=exception,
                     muteStackTrace=True)
             FlaskManager.raiseAndPersistGlobalException(
                 exception, resourceInstance, resourceMethod)
         if not muteLogs:
             log.debug(
                 resourceMethod,
                 f'{resourceMethod.shedulerId} scheduler finished')
         return methodReturn
     if not muteLogs:
         log.warning(
             resourceMethod,
             f'{resourceMethod.shedulerId} scheduler didn{c.SINGLE_QUOTE}t started. {"Schedulers are disabled" if not resourceInstance.enabled else "This scheduler is disabled" if resourceInstance.disabled else "This scheduler method is disabled"}'
         )