Exemplo n.º 1
0
    def _wrapper(*args, **kwargs):
        started_at = time.time()

        exit_code = GlobalConstants.DEFAULT_EXIT_CODE
        try:
            exit_code = func(*args, **kwargs)
        except Exception as e:
            emsg = "Error executing function {f} with {c}".format(f=func.__name__, c=e.__class__)
            log.exception(emsg)
            slog.error(e)

            type_, value_, traceback_ = sys.exc_info()

            log_traceback(slog, e, traceback_)
            log_traceback(log, e, traceback_)

            exit_code = GlobalConstants.EXCEPTION_TO_EXIT_CODE.get(e.__class__, GlobalConstants.DEFAULT_EXIT_CODE)
            print "Exit code from {e} class {c}".format(e=exit_code, c=e.__class__)

        finally:
            print "Shutting down."
            run_time = time.time() - started_at
            run_time_min = run_time / 60.0
            _m = {
                0: "was Successful",
                7: "was Terminated"
            }.get(exit_code, "Failed")
            _d = dict(s=_m, r=run_time, x=pbsmrtpipe.get_version(), m=run_time_min, c=exit_code)
            msg = "Completed execution pbsmrtpipe v{x}. Workflow {s} in {r:.2f} sec ({m:.2f} min) with exit code {c}".format(**_d)

            slog.info(msg)
            log.info(msg)

        return exit_code
Exemplo n.º 2
0
    def _wrapper(*args, **kwargs):
        started_at = time.time()

        state = False
        try:
            state = func(*args, **kwargs)
        except Exception as e:
            emsg = "Error executing function {f}".format(f=func.__name__)
            log.exception(emsg)
            slog.error(e)

            type_, value_, traceback_ = sys.exc_info()

            log_traceback(slog, e, traceback_)
            log_traceback(log, e, traceback_)

            state = False

        finally:
            print "Shutting down."
            run_time = time.time() - started_at
            run_time_min = run_time / 60.0
            _m = "was Successful" if state else "Failed"
            msg = "Completed execution pbsmrtpipe v{x}. Workflow {s} in {r:.2f} sec ({m:.2f} min)".format(s=_m, r=run_time, x=pbsmrtpipe.get_version(), m=run_time_min)

            slog.info(msg)
            log.info(msg)

        return 0 if state else 1