def standard(self) -> RunModel:
        jobs = []

        s = DateUtil.parse_iso(self.meta.get("start"))
        f = DateUtil.parse_iso(self.meta.get("end"))
        st = 0
        if s:
            ff = f if f else DateUtil.now()
            st = int(DateUtil.secs_difference(s, ff))

        jid = self.meta.get("id")
        for stepname, call in self.meta.get("calls").items():
            stepname = ".".join(stepname.split(".")[1:])
            jobs.extend(self.parse_standard_calls(None, stepname, call))

        model = RunModel(
            submission_id=None,
            id_=None,
            engine_id=jid,
            name=self.meta.get("workflowName"),
            # start=s,
            # finish=f,
            execution_dir=self.meta.get("workflowRoot"),
            status=cromwell_status_to_status(self.meta.get("status")),
            error=self.get_caused_by_text(),
        )
        model.jobs = jobs
        return model
Ejemplo n.º 2
0
    def format(
        self,
        pre,
        monochrome=False,
        brief=False,
        layer=0,
        njobs_in_parent=None,
        **kwargs,
    ):

        tb = "    "
        fin = self.finish if self.finish else DateUtil.now()
        time = round(DateUtil.secs_difference(self.start, fin)) if self.start else None
        # percentage = (
        #     (round(1000 * time / self.supertime) / 10)
        #     if (self.start and self.supertime)
        #     else None
        # )
        status = self.status or (
            sorted(self.events, key=lambda e: e.timestamp)[-1].status
            if self.events
            else TaskStatus.PROCESSING
        )

        name = self.name
        opts = []
        if self.shard is not None and self.shard >= 0:
            opts.append(f"shard-{self.shard}")
        if self.attempt and self.attempt > 1:
            opts.append(f"attempt-{self.attempt}")
        if len(opts) > 0:
            name += f" ({', '.join(opts)})"

        standard = pre + f"[{status.symbol()}] {name} ({second_formatter(time)})"

        col = ""
        uncol = ""

        if not monochrome:
            if status == TaskStatus.FAILED:
                col = _bcolors.FAIL
            elif status == TaskStatus.COMPLETED:
                col = _bcolors.OKGREEN
            # else:
            # col = _bcolors.UNDERLINE
            uncol = _bcolors.ENDC

        if (
            status != TaskStatus.COMPLETED
            or brief is False
            or (layer == 0 and njobs_in_parent == 1)
        ):
            if self.jobs:
                ppre = pre + tb
                subs: List[RunJobModel] = sorted(
                    self.jobs,
                    key=lambda j: (
                        j.shard or 0,
                        j.start if j.start else DateUtil.now(),
                    ),
                    reverse=False,
                )

                return (
                    col
                    + standard
                    + "".join(
                        [
                            "\n"
                            + j.format(
                                ppre, monochrome, brief, layer=layer + 1, **kwargs
                            )
                            for j in subs
                        ]
                    )
                    + uncol
                )

        fields: List[Tuple[str, str]] = []

        if status == TaskStatus.COMPLETED:
            if not self.finish:
                raise Exception(f"Finish was null for completed task: {self.name}")
            if self.cached:
                fields.append(("from cache", str(self.cached)))

        elif status == TaskStatus.RUNNING:
            fields.extend([("batchid", self.batchid), ("backend", self.backend)])

        elif status == TaskStatus.FAILED:
            if str(self.returncode) != "0":
                fields.append(["rc", str(self.returncode)])
            if self.stderr is not None:
                fields.append(("stderr", self.stderr))
            if self.error:
                fields.append(("error", self.error))
        elif status == TaskStatus.PROCESSING:
            pass
        elif status == TaskStatus.QUEUED:
            pass

        else:
            return (
                standard
                + f" :: Unimplemented status: '{status}' for task: '{self.name}'"
            )

        ppre = "\n" + " " * len(pre) + 2 * tb

        max_row_header_length = 0
        if len(fields) > 0:
            max_row_header_length = max(len(t[0]) for t in fields) + 0

        retval = standard + "".join(
            f"{ppre}{f[0]}:{' ' * (max_row_header_length - len(f[0]))} {f[1]}"
            for f in fields
            if f[1]
        )

        return col + retval + uncol