示例#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()
示例#2
0
    def run(self, *args, **kwargs):
        try:
            # TODO : Support unicode
            args, kwargs = self.convertUnicodeArgs(args, kwargs)
            ctask = task.Task(id=None, name=self.name)
            vars.task = ctask
            try:
                response = self.STATUS_OK.copy()
                result = ctask.prepare(self.func, *args, **kwargs)
                if type(result) == dict:
                    response.update(result)
                return response
            except se.GeneralException, e:
                self.log.error(e.response())
                return e.response()
            except BaseException, 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)
示例#3
0
文件: dispatcher.py 项目: ekohl/vdsm
    def run(self, *args, **kwargs):
        try:
            # TODO : Support unicode
            args, kwargs = self.convertUnicodeArgs(args, kwargs)
            ctask = task.Task(id=None, name=self.name)
            vars.task = ctask
            try:
                response = self.STATUS_OK.copy()
                result = ctask.prepare(self.func, *args, **kwargs)
                if type(result) == dict:
                    response.update(result)
                return response
            except se.GeneralException, e:
                self.log.error(e.response())
                return e.response()
            except BaseException, 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)