Skip to main content

prefect.states

Functions

to_state_create

Convert the state to a StateCreate type which can be used to set the state of a run in the API. This method will drop this state’s data if it is not a result type. Only results should be sent to the API. Other data is only available locally.

get_state_result

Get the result from a state. See State.result()

format_exception

exception_to_crashed_state

Takes an exception that occurs outside of user code and converts it to a ‘Crash’ exception with a ‘Crashed’ state.

exception_to_failed_state

Convenience function for creating Failed states from exceptions

return_value_to_state

Given a return value from a user’s function, create a State the run should be placed in.
  • If data is returned, we create a ‘COMPLETED’ state with the data
  • If a single, manually created state is returned, we use that state as given (manual creation is determined by the lack of ids)
  • If an upstream state or iterable of upstream states is returned, we apply the aggregate rule
The aggregate rule says that given multiple states we will determine the final state such that:
  • If any states are not COMPLETED the final state is FAILED
  • If all of the states are COMPLETED the final state is COMPLETED
  • The states will be placed in the final state data attribute
Callers should resolve all futures into states before passing return values to this function.

aget_state_exception

Get the exception from a state asynchronously. If not given a FAILED or CRASHED state, this raise a value error. If the state result is a state, its exception will be returned. If the state result is an iterable of states, the exception of the first failure will be returned. If the state result is a string, a wrapper exception will be returned with the string as the message. If the state result is null, a wrapper exception will be returned with the state message attached. If the state result is not of a known type, a TypeError will be returned. When a wrapper exception is returned, the type will be:
  • FailedRun if the state type is FAILED.
  • CrashedRun if the state type is CRASHED.
  • CancelledRun if the state type is CANCELLED.

get_state_exception

Get the exception from a state. If not given a FAILED or CRASHED state, this raise a value error. If the state result is a state, its exception will be returned. If the state result is an iterable of states, the exception of the first failure will be returned. If the state result is a string, a wrapper exception will be returned with the string as the message. If the state result is null, a wrapper exception will be returned with the state message attached. If the state result is not of a known type, a TypeError will be returned. When a wrapper exception is returned, the type will be:
  • FailedRun if the state type is FAILED.
  • CrashedRun if the state type is CRASHED.
  • CancelledRun if the state type is CANCELLED.

araise_state_exception

Given a FAILED or CRASHED state, raise the contained exception asynchronously.

raise_state_exception

Given a FAILED or CRASHED state, raise the contained exception.

is_state_iterable

Check if a the given object is an iterable of states types Supported iterables are:
  • set
  • list
  • tuple
Other iterables will return False even if they contain states.

Scheduled

Convenience function for creating Scheduled states. Returns:
  • a Scheduled state

Completed

Convenience function for creating Completed states. Returns:
  • a Completed state

Running

Convenience function for creating Running states. Returns:
  • a Running state

Failed

Convenience function for creating Failed states. Returns:
  • a Failed state

Crashed

Convenience function for creating Crashed states. Returns:
  • a Crashed state

Cancelling

Convenience function for creating Cancelling states. Returns:
  • a Cancelling state

Cancelled

Convenience function for creating Cancelled states. Returns:
  • a Cancelled state

Pending

Convenience function for creating Pending states. Returns:
  • a Pending state

Paused

Convenience function for creating Paused states. Returns:
  • a Paused state

Suspended

Convenience function for creating Suspended states. Returns:
  • a Suspended state

AwaitingRetry

Convenience function for creating AwaitingRetry states. Returns:
  • an AwaitingRetry state

AwaitingConcurrencySlot

Convenience function for creating AwaitingConcurrencySlot states. Returns:
  • an AwaitingConcurrencySlot state

Submitting

Convenience function for creating Submitting states. Returns:
  • a Submitting state

InfrastructurePending

Convenience function for creating InfrastructurePending states. Returns:
  • an InfrastructurePending state

Retrying

Convenience function for creating Retrying states. Returns:
  • a Retrying state

Late

Convenience function for creating Late states. Returns:
  • a Late state

Classes

StateGroup

Methods:

all_completed

all_final

any_cancelled

any_failed

any_paused

counts_message

fail_count