Skip to content

batch_handler

Helper decorator to catch exceptions and save the state before exiting.

batch_handler(batch_function)

Provides the state to the batch function and ensures the state is saved if an exception is thrown.

Source code in dapla_team_cli/pr/batch_handler.py
 9
10
11
12
13
14
15
16
17
18
19
def batch_handler(batch_function: Callable[..., Any]) -> Callable[..., Any]:
    """Provides the state to the batch function and ensures the state is saved if an exception is thrown."""

    def exception_handler(*args: Any, **kwargs: Any) -> None:
        try:
            batch_function(*args, **kwargs)
        finally:
            if state := state_object_handler.current_state:
                state_object_handler.set_state(state=state)

    return exception_handler