prefect.server.orchestration.global_policy

Bookkeeping logic that fires on every state transition. For clarity, GlobalFlowpolicy and GlobalTaskPolicy contain all transition logic implemented using BaseUniversalTransform. None of these operations modify state, and regardless of what orchestration Prefect REST API might enforce on a transition, the global policies contain Prefect’s necessary bookkeeping. Because these transforms record information about the validated state committed to the state database, they should be the most deeply nested contexts in orchestration loop.

Functions

COMMON_GLOBAL_TRANSFORMS

COMMON_GLOBAL_TRANSFORMS() -> list[type[BaseUniversalTransform[orm_models.Run, Union[core.FlowRunPolicy, core.TaskRunPolicy]]]]

Classes

GlobalFlowPolicy

Global transforms that run against flow-run-state transitions in priority order. These transforms are intended to run immediately before and after a state transition is validated. Methods:

priority

priority() -> list[Union[type[BaseUniversalTransform[orm_models.FlowRun, core.FlowRunPolicy]], type[BaseOrchestrationRule[orm_models.FlowRun, core.FlowRunPolicy]]]]

GlobalTaskPolicy

Global transforms that run against task-run-state transitions in priority order. These transforms are intended to run immediately before and after a state transition is validated. Methods:

priority

priority() -> list[Union[type[BaseUniversalTransform[orm_models.TaskRun, core.TaskRunPolicy]], type[BaseOrchestrationRule[orm_models.TaskRun, core.TaskRunPolicy]]]]

SetRunStateType

Updates the state type of a run on a state transition. Methods:

before_transition

before_transition(self, context: GenericOrchestrationContext[orm_models.Run, Any]) -> None

SetRunStateName

Updates the state name of a run on a state transition. Methods:

before_transition

before_transition(self, context: GenericOrchestrationContext[orm_models.Run, Any]) -> None

SetStartTime

Records the time a run enters a running state for the first time. Methods:

before_transition

before_transition(self, context: GenericOrchestrationContext[orm_models.Run, Any]) -> None

SetRunStateTimestamp

Records the time a run changes states. Methods:

before_transition

before_transition(self, context: GenericOrchestrationContext[orm_models.Run, Any]) -> None

SetEndTime

Records the time a run enters a terminal state. With normal client usage, a run will not transition out of a terminal state. However, it’s possible to force these transitions manually via the API. While leaving a terminal state, the end time will be unset. Methods:

before_transition

before_transition(self, context: GenericOrchestrationContext[orm_models.Run, Any]) -> None

IncrementRunTime

Records the amount of time a run spends in the running state. Methods:

before_transition

before_transition(self, context: GenericOrchestrationContext[orm_models.Run, Any]) -> None

IncrementFlowRunCount

Records the number of times a run enters a running state. For use with retries. Methods:

before_transition

before_transition(self, context: OrchestrationContext[orm_models.FlowRun, core.FlowRunPolicy]) -> None

RemoveResumingIndicator

Removes the indicator on a flow run that marks it as resuming. Methods:

before_transition

before_transition(self, context: OrchestrationContext[orm_models.FlowRun, core.FlowRunPolicy]) -> None

IncrementTaskRunCount

Records the number of times a run enters a running state. For use with retries. Methods:

before_transition

before_transition(self, context: OrchestrationContext[orm_models.TaskRun, core.TaskRunPolicy]) -> None

SetExpectedStartTime

Estimates the time a state is expected to start running if not set. For scheduled states, this estimate is simply the scheduled time. For other states, this is set to the time the proposed state was created by Prefect. Methods:

before_transition

before_transition(self, context: GenericOrchestrationContext[orm_models.Run, Any]) -> None

SetNextScheduledStartTime

Records the scheduled time on a run. When a run enters a scheduled state, run.next_scheduled_start_time is set to the state’s scheduled time. When leaving a scheduled state, run.next_scheduled_start_time is unset. Methods:

before_transition

before_transition(self, context: GenericOrchestrationContext[orm_models.Run, Any]) -> None

UpdateSubflowParentTask

Whenever a subflow changes state, it must update its parent task run’s state. Methods:

after_transition

after_transition(self, context: OrchestrationContext[orm_models.FlowRun, core.FlowRunPolicy]) -> None

UpdateSubflowStateDetails

Update a child subflow state’s references to a corresponding tracking task run id in the parent flow run Methods:

before_transition

before_transition(self, context: OrchestrationContext[orm_models.FlowRun, core.FlowRunPolicy]) -> None

UpdateStateDetails

Update a state’s references to a corresponding flow- or task- run. Methods:

before_transition

before_transition(self, context: GenericOrchestrationContext) -> None