# FlowRunner


# FlowRunner

class

prefect.engine.flow_runner.FlowRunner

(flow, task_runner_cls=None, state_handlers=None)[source]

FlowRunners handle the execution of Flows and determine the State of a Flow before, during and after the Flow is run.

In particular, through the FlowRunner you can specify which tasks should be the first tasks to run, which tasks should be returned after the Flow is finished, and what states each task should be initialized with.

Args:

  • flow (Flow): the Flow to be run
  • task_runner_cls (TaskRunner, optional): The class used for running individual Tasks. Defaults to TaskRunner
  • state_handlers (Iterable[Callable], optional): A list of state change handlers that will be called whenever the flow changes state, providing an opportunity to inspect or modify the new state. The handler will be passed the flow runner instance, the old (prior) state, and the new (current) state, with the following signature: state_handler(fr: FlowRunner, old_state: State, new_state: State) -> Optional[State] If multiple functions are passed, then the new_state argument will be the result of the previous handler.
Note: new FlowRunners are initialized within the call to Flow.run() and in general, this is the endpoint through which FlowRunners will be interacted with most frequently.

Example:

@task
def say_hello():
    print('hello')

with Flow("My Flow") as f:
    say_hello()

fr = FlowRunner(flow=f)
flow_state = fr.run()

methods:                                                                                                                                                       

prefect.engine.flow_runner.FlowRunner.call_runner_target_handlers

(old_state, new_state)[source]

A special state handler that the FlowRunner uses to call its flow's state handlers. This method is called as part of the base Runner's handle_state_change() method.

Args:

  • old_state (State): the old (previous) state
  • new_state (State): the new (current) state
Returns:
  • State: the new state

prefect.engine.flow_runner.FlowRunner.check_flow_is_pending_or_running

(state)[source]

Checks if the flow is in either a Pending state or Running state. Either are valid starting points (because we allow simultaneous runs of the same flow run).

Args:

  • state (State): the current state of this flow
Returns:
  • State: the state of the flow after running the check
Raises:
  • ENDRUN: if the flow is not pending or running

prefect.engine.flow_runner.FlowRunner.check_flow_reached_start_time

(state)[source]

Checks if the Flow is in a Scheduled state and, if it is, ensures that the scheduled time has been reached.

Args:

  • state (State): the current state of this Flow
Returns:
  • State: the state of the flow after performing the check
Raises:
  • ENDRUN: if the flow is Scheduled with a future scheduled time

prefect.engine.flow_runner.FlowRunner.check_for_cancellation

()[source]

Contextmanager used to wrap a cancellable section of a flow run.

No-op for the default FlowRunner class.

prefect.engine.flow_runner.FlowRunner.determine_final_state

(state, key_states, return_states, terminal_states)[source]

Implements the logic for determining the final state of the flow run.

Args:

  • state (State): the current state of the Flow
  • key_states (Set[State]): the states which will determine the success / failure of the flow run
  • return_states (Dict[Task, State]): states to return as results
  • terminal_states (Set[State]): the states of the terminal tasks for this flow
Returns:
  • State: the final state of the flow run

prefect.engine.flow_runner.FlowRunner.get_flow_run_state

(state, task_states, task_contexts, return_tasks, task_runner_state_handlers, executor)[source]

Runs the flow.

Args:

  • state (State): starting state for the Flow. Defaults to Pending
  • task_states (dict): dictionary of task states to begin computation with, with keys being Tasks and values their corresponding state
  • task_contexts (Dict[Task, Dict[str, Any]]): contexts that will be provided to each task
  • return_tasks ([Task], optional): list of Tasks to include in the final returned Flow state. Defaults to None
  • task_runner_state_handlers (Iterable[Callable]): A list of state change handlers that will be provided to the task_runner, and called whenever a task changes state.
  • executor (Executor): executor to use when performing computation; defaults to the executor provided in your prefect configuration
Returns:
  • State: State representing the final post-run state of the Flow.

prefect.engine.flow_runner.FlowRunner.initialize_run

(state, task_states, context, task_contexts, parameters)[source]

Initializes the Task run by initializing state and context appropriately.

If the provided state is a Submitted state, the state it wraps is extracted.

Args:

  • state (Optional[State]): the initial state of the run
  • task_states (Dict[Task, State]): a dictionary of any initial task states
  • context (Dict[str, Any], optional): prefect.Context to use for execution to use for each Task run
  • task_contexts (Dict[Task, Dict[str, Any]], optional): contexts that will be provided to each task
  • parameters(dict): the parameter values for the run
Returns:
  • NamedTuple: a tuple of initialized objects: (state, task_states, context, task_contexts)

prefect.engine.flow_runner.FlowRunner.run

(state=None, task_states=None, return_tasks=None, parameters=None, task_runner_state_handlers=None, executor=None, context=None, task_contexts=None)[source]

The main endpoint for FlowRunners. Calling this method will perform all computations contained within the Flow and return the final state of the Flow.

Args:

  • state (State, optional): starting state for the Flow. Defaults to Pending
  • task_states (dict, optional): dictionary of task states to begin computation with, with keys being Tasks and values their corresponding state
  • return_tasks ([Task], optional): list of Tasks to include in the final returned Flow state. Defaults to None
  • parameters (dict, optional): dictionary of any needed Parameter values, with keys being strings representing Parameter names and values being their corresponding values
  • task_runner_state_handlers (Iterable[Callable], optional): A list of state change handlers that will be provided to the task_runner, and called whenever a task changes state.
  • executor (Executor, optional): executor to use when performing computation; defaults to the executor specified in your prefect configuration
  • context (Dict[str, Any], optional): prefect.Context to use for execution to use for each Task run
  • task_contexts (Dict[Task, Dict[str, Any]], optional): contexts that will be provided to each task
Returns:
  • State: State representing the final post-run state of the Flow.

prefect.engine.flow_runner.FlowRunner.set_flow_to_running

(state)[source]

Puts Pending flows in a Running state; leaves Running flows Running.

Args:

  • state (State): the current state of this flow
Returns:
  • State: the state of the flow after running the check
Raises:
  • ENDRUN: if the flow is not pending or running



This documentation was auto-generated from commit n/a
on July 1, 2021 at 18:35 UTC