Ejemplo n.º 1
0
        def wrapper(*args, **kwargs):
            try:
                ctask = task.Task(id=None, name=name)
                try:
                    response = self.STATUS_OK.copy()
                    result = ctask.prepare(func, *args, **kwargs)
                    if type(result) == dict:
                        response.update(result)
                    return response
                except se.GeneralException as e:
                    self.log.error(e.response())
                    return e.response()
                except BaseException as e:
                    self.log.error(e, exc_info=True)
                    defaultException = ctask.defaultException
                    if (defaultException and
                            hasattr(defaultException, "response")):
                        resp = defaultException.response()
                        defaultExceptionInfo = (resp['status']['code'],
                                                resp['status']['message'])
                        return se.generateResponse(e, defaultExceptionInfo)

                    return se.generateResponse(e)
            except:
                try:
                    self.log.error(
                        "Unhandled exception in run and protect: %s, "
                        "args: %s ", self.name, args, exc_info=True)
                finally:
                    return self.STATUS_ERROR.copy()
Ejemplo n.º 2
0
        def wrapper(*args, **kwargs):
            try:
                ctask = task.Task(id=None, name=name)
                try:
                    response = self.STATUS_OK.copy()
                    result = ctask.prepare(func, *args, **kwargs)
                    if type(result) == dict:
                        response.update(result)
                    return response
                except se.GeneralException as e:
                    # Match api.method format
                    self.log.error("FINISH %s error=%s", name, e)
                    return e.response()
                except BaseException as e:
                    # Match api.method format
                    self.log.exception("FINISH %s error=%s", name, e)
                    defaultException = ctask.defaultException
                    if (defaultException and
                            hasattr(defaultException, "response")):
                        resp = defaultException.response()
                        defaultExceptionInfo = (resp['status']['code'],
                                                resp['status']['message'])
                        return se.generateResponse(e, defaultExceptionInfo)

                    return se.generateResponse(e)
            except:
                try:
                    # We should never reach this
                    self.log.exception(
                        "Unhandled exception (name=%s, args=%s, kwargs=%s)",
                        name, args, kwargs)
                finally:
                    return self.STATUS_ERROR.copy()
Ejemplo n.º 3
0
        def wrapper(*args, **kwargs):
            try:
                ctask = task.Task(id=None, name=name)
                try:
                    response = self.STATUS_OK.copy()
                    result = ctask.prepare(func, *args, **kwargs)
                    if type(result) == dict:
                        response.update(result)
                    return response
                except se.GeneralException as e:
                    self.log.error(e.response())
                    return e.response()
                except BaseException as e:
                    self.log.error(e, exc_info=True)
                    defaultException = ctask.defaultException
                    if (defaultException
                            and hasattr(defaultException, "response")):
                        resp = defaultException.response()
                        defaultExceptionInfo = (resp['status']['code'],
                                                resp['status']['message'])
                        return se.generateResponse(e, defaultExceptionInfo)

                    return se.generateResponse(e)
            except:
                try:
                    self.log.error(
                        "Unhandled exception in run and protect: %s, "
                        "args: %s ",
                        self.name,
                        args,
                        exc_info=True)
                finally:
                    return self.STATUS_ERROR.copy()
Ejemplo n.º 4
0
        def wrapper(*args, **kwargs):
            try:
                ctask = task.Task(id=None, name=name)
                try:
                    response = self.STATUS_OK.copy()
                    result = ctask.prepare(func, *args, **kwargs)
                    if type(result) == dict:
                        response.update(result)
                    return response
                except se.GeneralException as e:
                    # Match api.method format
                    self.log.error("FINISH %s error=%s", name, e)
                    return e.response()
                except BaseException as e:
                    # Match api.method format
                    self.log.exception("FINISH %s error=%s", name, e)
                    defaultException = ctask.defaultException
                    if (defaultException
                            and hasattr(defaultException, "response")):
                        resp = defaultException.response()
                        defaultExceptionInfo = (resp['status']['code'],
                                                resp['status']['message'])
                        return se.generateResponse(e, defaultExceptionInfo)

                    return se.generateResponse(e)
            except:
                try:
                    # We should never reach this
                    self.log.exception(
                        "Unhandled exception (name=%s, args=%s, kwargs=%s)",
                        name, args, kwargs)
                finally:
                    return self.STATUS_ERROR.copy()