Ejemplo n.º 1
0
async def cancel_flow_run(flow_run_id: str) -> models.FlowRun:
    """
    Cancel a flow run.

    If the flow run is already finished, this is a no-op.

    Args:
        - flow_run_id (str): the flow run to cancel
    """
    if not flow_run_id:
        raise ValueError("Invalid flow run ID.")

    flow_run = await models.FlowRun.where(id=flow_run_id).first(
        {"id", "state", "serialized_state"})
    if not flow_run:
        raise ValueError(f"Invalid flow run ID: {flow_run_id}.")

    state = state_schema.load(flow_run.serialized_state)

    if state.is_finished():
        return flow_run
    else:
        if state.is_running():
            state = Cancelling("Flow run is cancelling")
        else:
            state = Cancelled("Flow run is cancelled")
        return await set_flow_run_state(flow_run_id=flow_run_id, state=state)
Ejemplo n.º 2
0
        def get_flow_run_info(*args, _call_count=itertools.count(), **kwargs):
            call_count = next(_call_count)
            import inspect

            caller_name = inspect.currentframe().f_back.f_code.co_name
            if caller_name == "interrupt_if_cancelling" and call_count % 2:
                nonlocal error_was_raised
                error_was_raised = True
                raise ValueError("Woops!")
            state = Cancelling() if trigger.is_set() else Running()
            return MagicMock(version=call_count, state=state)
Ejemplo n.º 3
0
 def get_flow_run_info(*args, _version=itertools.count(), **kwargs):
     state = Cancelling() if trigger.is_set() else Running()
     return MagicMock(version=next(_version), state=state)