def _decorate()

in src/hpc/autoscale/node/nodehistory.py [0:0]


    def _decorate(self, nodes: typing.List[Node], config: typing.Dict = {}) -> None:
        if not nodes:
            nodes = []

        nodes = [n for n in nodes if n.exists]
        equalities = [
            " (node_id == '{}') ".format(n.delayed_node_id.node_id) for n in nodes
        ]

        if not equalities:
            return

        stmt = "select node_id, create_time, last_match_time, ready_time, delete_time from nodes where {}".format(
            "{}".format(" OR ".join(equalities))
        )

        rows = self._execute(stmt)
        rows_by_id = partition_single(list(rows), lambda r: r[0])

        now = self.now()

        for node in nodes:
            node_id = node.delayed_node_id.node_id

            # should be impossible because we already filtered by exists
            if not node_id:
                logging.warning(
                    "Null node_id for %s. Leaving create/last_match/delete times as null.",
                    node,
                )
                continue

            if node_id in rows_by_id:

                (
                    node_id,
                    create_time,
                    last_match_time,
                    ready_time,
                    delete_time,
                ) = rows_by_id[node_id]

                node.create_time_unix = create_time
                node.last_match_time_unix = last_match_time
                node.delete_time_unix = delete_time
                boot_timeout = parse_boot_timeout(config, node)
                idle_timeout = parse_idle_timeout(config, node)
                if boot_timeout:
                    if ready_time < 1:
                        create_elapsed = max(0, now - create_time)
                        create_remaining = max(0, boot_timeout - create_elapsed)
                        node.create_time_remaining = create_remaining

                if idle_timeout:
                    if node.keep_alive or node.state != "Ready":
                        node.idle_time_remaining = -1
                    else:
                        match_elapsed = max(0, now - last_match_time)
                        match_remaining = max(0, idle_timeout - match_elapsed)
                        node.idle_time_remaining = match_remaining