Skip to main content

prefect.task_engine

Functions

run_task_sync

run_task_async

run_generator_task_sync

run_generator_task_async

run_task

Runs the provided task. Args:
  • task: The task to run
  • task_run_id: The ID of the task run; if not provided, a new task run will be created
  • task_run: The task run object; if not provided, a new task run will be created
  • parameters: The parameters to pass to the task
  • wait_for: A list of futures to wait for before running the task
  • return_type: The return type to return; either “state” or “result”
  • dependencies: A dictionary of task run inputs to use for dependency tracking
  • context: A dictionary containing the context to use for the task run; only required if the task is running on in a remote environment
Returns:
  • The result of the task run

Classes

TaskRunTimeoutError

Raised when a task run exceeds its timeout.

BaseTaskRunEngine

Methods:

compute_transaction_key

handle_rollback

is_cancelled

is_running

Whether or not the engine is currently running a task.

log_finished_message

record_terminal_state_timing

state

SyncTaskRunEngine

Methods:

asset_context

begin_run

call_hooks

call_task_fn

Convenience method to call the task function. Returns a coroutine if the task is async.

can_retry

client

handle_crash

handle_exception

handle_retry

Handle any task run retries.
  • If the task has retries left, and the retry condition is met, set the task to retrying and return True.
  • If the task has a retry delay, place in AwaitingRetry state with a delayed scheduled time.
  • If the task has no retries left, or the retry condition is not met, return False.

handle_success

handle_timeout

initialize_run

Enters a client context and creates a task run if needed.

result

run_context

set_state

setup_run_context

start

transaction_context

wait_until_ready

Sync version: Waits until the scheduled time (if its the future), then enters Running.

AsyncTaskRunEngine

Methods:

asset_context

begin_run

call_hooks

call_task_fn

Convenience method to call the task function. Returns a coroutine if the task is async.

can_retry

client

handle_crash

handle_exception

handle_retry

Handle any task run retries.
  • If the task has retries left, and the retry condition is met, set the task to retrying and return True.
  • If the task has a retry delay, place in AwaitingRetry state with a delayed scheduled time.
  • If the task has no retries left, or the retry condition is not met, return False.

handle_success

handle_timeout

initialize_run

Enters a client context and creates a task run if needed.

result

run_context

set_state

setup_run_context

start

transaction_context

wait_until_ready

Waits until the scheduled time (if its the future), then enters Running.