Skip to content

hyfi.runner

Runner

Bases: BatchTask

Source code in hyfi/runner/base.py
class Runner(BatchTask):
    _config_group_: str = "/runner"
    _config_name_: str = "__init__"

    calls: Optional[List[Union[str, Dict]]] = []

    def __call__(self) -> None:
        self.run()

    def run(self):
        self.run_calls()

    def get_running_calls(self) -> RunningCalls:
        return get_running_configs(self.calls or [])

    def run_call(self, rc: Running) -> None:
        method_ = getattr(self, rc.uses, None)
        if method_ and callable(method_):
            method_(**rc.run_kwargs)

    def run_calls(self):
        """
        Run the calls specified in the runner
        """
        calls = self.get_running_calls()
        if self.verbose:
            logger.info("Running %s call(s)", len(calls))
        # Run all calls in the runner
        with elapsed_timer(format_time=True) as elapsed:
            for rc in calls:
                logger.info("Running call [%s] with [%s]", rc.uses, rc.run_kwargs)
                self.run_call(rc)
            if self.verbose:
                logger.info(
                    " >> elapsed time for the runner with %s calls: %s",
                    len(self.calls or []),
                    elapsed(),
                )

run_calls()

Run the calls specified in the runner

Source code in hyfi/runner/base.py
def run_calls(self):
    """
    Run the calls specified in the runner
    """
    calls = self.get_running_calls()
    if self.verbose:
        logger.info("Running %s call(s)", len(calls))
    # Run all calls in the runner
    with elapsed_timer(format_time=True) as elapsed:
        for rc in calls:
            logger.info("Running call [%s] with [%s]", rc.uses, rc.run_kwargs)
            self.run_call(rc)
        if self.verbose:
            logger.info(
                " >> elapsed time for the runner with %s calls: %s",
                len(self.calls or []),
                elapsed(),
            )