Task execution

TaskExecutor chooses an execution strategy from the scheme of the route (task:// or lambda://). To support a new scheme, subclass TaskExecutionStrategy and register it in TaskExecutor.strategies.

Executor

class celery_cloud.runners.task_executor.TaskExecutor[source]

Bases: object

__init__() → None[source]
execute(task: Task, route: TaskRoute) → Any[source]

Strategy interface

class celery_cloud.runners.task_execution_strategy.TaskExecutionStrategy[source]

Bases: ABC

abstractmethod execute(task: Task, route: TaskRoute) → Any[source]

Execute a task based on the strategy

Local strategy (task://)

class celery_cloud.runners.local_strategy.LocalTaskExecutionStrategy[source]

Bases: TaskExecutionStrategy

Run the task as a python function packaged with the runner.

The route is task://<module>/<function>. The function is called with two positional parameters: the list of positional arguments and the dict of keyword arguments, i.e. function(args, kwargs). A function decorated with celery_cloud.task is called with its natural arguments instead (see celery_cloud.tasks).

execute(task: Task, route: TaskRoute) → Any[source]

Execute a task based on the strategy

celery_cloud.runners.local_strategy.load_function(route: TaskRoute) → Any[source]

Import the function of a task://<module>/<function> route.

Module and function come from the TASKS setting (trusted, deployed with the runner), never from the message.

celery_cloud.runners.local_strategy.task_options(route: TaskRoute) → TaskOptions | None[source]

The @task options of a local route (None for a plain function).

Best effort: if the function cannot be imported, None is returned and executing the task reports the real error.

Lambda strategy (lambda://)

exception celery_cloud.runners.lambda_strategy.LambdaFunctionError(message: str, detail: str | None = None)[source]

Bases: TaskExecutionException

The remote function ran and reported an error.

It is neither retried (the code already executed and may have side effects) nor counted by the circuit breaker (it is a business error, not an infrastructure failure).

exception celery_cloud.runners.lambda_strategy.LambdaInvocationError(message: str, detail: str | None = None)[source]

Bases: TaskExecutionException

The remote function could not be invoked (throttling, network…).

It is safe to retry: the function did not run.

class celery_cloud.runners.lambda_strategy.LambdaTaskExecutionStrategy[source]

Bases: TaskExecutionStrategy

execute(task: Task, route: TaskRoute) → Any[source]

Execute a task based on the strategy

celery_cloud.runners.lambda_strategy.get_breaker(function_arn: str) → CircuitBreaker[source]

Get (or create) the circuit breaker of a remote function.