Entities

Pydantic models for the SQS event, the Celery task and the response returned by the handler.

SQS event and messages

class celery_cloud.entities.sqs_entities.DeliveryInfo(*, exchange: str, routing_key: str)[source]

Bases: BaseModel

Delivery information for the SQS message.

exchange: str
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

routing_key: str
class celery_cloud.entities.sqs_entities.Headers(*, lang: str, task: str, id: str, shadow: str | None = None, eta: str | None = None, expires: str | None = None, group: str | None = None, group_index: int | None = None, compression: str | None = None, retries: int = 0, timelimit: list[float | None] = <factory>, root_id: str | None = None, parent_id: str | None = None, argsrepr: str | None = None, kwargsrepr: str | None = None, origin: str | None = None, ignore_result: bool = False, replaced_task_nesting: int = 0, stamped_headers: Any | None = None, stamps: dict[str, ~typing.Any]=<factory>)[source]

Bases: BaseModel

Metadata headers for the Celery task.

argsrepr: str | None
compression: str | None
eta: str | None
expires: str | None
group: str | None
group_index: int | None
id: str
ignore_result: bool
kwargsrepr: str | None
lang: str
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

origin: str | None
parent_id: str | None
replaced_task_nesting: int
retries: int
root_id: str | None
shadow: str | None
stamped_headers: Any | None
stamps: dict[str, Any]
task: str
timelimit: list[float | None]
class celery_cloud.entities.sqs_entities.Properties(*, correlation_id: str | None = None, reply_to: str | None = None, delivery_mode: int | None = None, delivery_info: DeliveryInfo | None = None, priority: int | None = None, body_encoding: str = 'base64', delivery_tag: str | None = None)[source]

Bases: BaseModel

Properties of the SQS message.

body_encoding: str
correlation_id: str | None
delivery_info: DeliveryInfo | None
delivery_mode: int | None
delivery_tag: str | None
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

priority: int | None
reply_to: str | None
class celery_cloud.entities.sqs_entities.SQSAttributes(*, ApproximateReceiveCount: str, SentTimestamp: str, ApproximateFirstReceiveTimestamp: str)[source]

Bases: BaseModel

Metadata attributes of the SQS message.

ApproximateFirstReceiveTimestamp: str
ApproximateReceiveCount: str
SentTimestamp: str
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class celery_cloud.entities.sqs_entities.SQSEvent(*, Records: list[SQSRecord])[source]

Bases: BaseModel

Representation of an AWS SQS event.

Parameters:

BaseModel (_type_) – Pydantic base model.

Records: list[SQSRecord]
classmethod from_lambda(event: dict[str, Any]) → SQSEvent[source]

Get a SQSEvent from a lambda event

Parameters:

event (dict[str, Any]) – Lambda event

Returns:

Decoded event

Return type:

SQSEVent

model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class celery_cloud.entities.sqs_entities.SQSMessage(*, body: str, content_encoding: str, content_type: str, headers: Headers, properties: Properties)[source]

Bases: BaseModel

Model representing an SQS message containing a Celery task.

body: str
content_encoding: str
content_type: str
decode_body() → Any[source]

Decodes the message body into a Python object.

For Celery protocol 2 with the JSON serializer this is [args, kwargs, embed].

classmethod from_record(record: SQSRecord) → SQSMessage[source]

Build the message carried by an SQS record.

Raises:

MessageDecodeException – If the record body is not a valid Celery message envelope.

get_task() → Task[source]

Get the Celery Task carried by this message.

The arguments are read from the message body, never from the argsrepr/kwargsrepr headers: those are truncated, log-oriented representations that cannot be trusted to rebuild the arguments.

Raises:

TaskDecodeException – If the body or headers are not a valid task.

headers: Headers
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

properties: Properties
class celery_cloud.entities.sqs_entities.SQSRecord(*, messageId: str, receiptHandle: str, body: str, attributes: SQSAttributes, eventSource: str, eventSourceARN: str)[source]

Bases: BaseModel

Model representing a single SQS message.

attributes: SQSAttributes
body: str
eventSource: str
eventSourceARN: str
get_message() → dict[str, Any][source]

Decodes the base64-encoded body into a JSON dictionary.

Raises:

MessageDecodeException – If the body is not base64 encoded JSON object.

messageId: str
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

receiptHandle: str

Task and route

class celery_cloud.entities.task.Task(*, task: Annotated[str, MaxLen(max_length=150)], id: Annotated[str, MaxLen(max_length=150)], args: list[Any], kwargs: dict[str, Any], retries: int | None = 0, eta: str | None = None, expires: str | None = None, ignore_result: bool = False, queue: str | None = None, parent_id: str | None = None, root_id: str | None = None, group: str | None = None, group_index: int | None = None, callbacks: list[dict[str, Any]] | None = None, errbacks: list[dict[str, Any]] | None = None, chain: list[dict[str, Any]] | None = None, chord: dict[str, Any] | None = None, time_limit: float | None = None, soft_time_limit: float | None = None)[source]

Bases: BaseModel

Representation of a celery SQS task

Parameters:

BaseModel (_type_) – _description_

args: list[Any]
callbacks: list[dict[str, Any]] | None
chain: list[dict[str, Any]] | None
chord: dict[str, Any] | None
errbacks: list[dict[str, Any]] | None
eta: str | None
eta_seconds(now: datetime | None = None) → float | None[source]

Seconds until eta (None when there is none or it is not valid).

expires: str | None
group: str | None
group_index: int | None
id: str
ignore_result: bool
is_expired(now: datetime | None = None) → bool[source]

True when the task has an expires time that already passed.

An unparseable value is treated as “does not expire” rather than discarding a task over a malformed header.

kwargs: dict[str, Any]
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

parent_id: str | None
queue: str | None
retries: int | None
root_id: str | None
soft_time_limit: float | None
task: str
time_limit: float | None
class celery_cloud.entities.task_route.TaskRoute(scheme: str, module: str, function: str, query: dict[str, list[str]])[source]

Bases: NamedTuple

Task decoded route

Parameters:

NamedTuple (_type_) – _description_

classmethod from_url(url: str) → TaskRoute[source]

Create a TaskRoute from a url

Parameters:

url (str) – Url to create route from

Returns:

TaskRoute instance

Return type:

TaskRoute

function: str

Alias for field number 2

module: str

Alias for field number 1

query: dict[str, list[str]]

Alias for field number 3

scheme: str

Alias for field number 0

class celery_cloud.entities.task_result.TaskResult(*, status: str, result: Any | None = None, traceback: str | None = None, children: list[Any] = <factory>, date_done: str | None = None, name: str | None = None, args: list[Any] | None = None, kwargs: dict[str, ~typing.Any] | None=None, worker: str | None = None, retries: int | None = None, queue: str | None = None, task_id: str)[source]

Bases: BaseModel

Model for the result of a task

Parameters:

BaseModel (_type_) – _description_

args: list[Any] | None
children: list[Any]
date_done: str | None
kwargs: dict[str, Any] | None
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str | None
queue: str | None
result: Any | None
retries: int | None
status: str
task_id: str
traceback: str | None
worker: str | None

Handler response

class celery_cloud.entities.lambda_response.BatchItemFailure(*, itemIdentifier: str)[source]

Bases: BaseModel

SQS partial batch response item: the message SQS must deliver again

itemIdentifier: str
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class celery_cloud.entities.lambda_response.DelayedTask(*, message_id: str, task_id: Annotated[str, MaxLen(max_length=150)], delay_seconds: int)[source]

Bases: BaseModel

A task held back until its eta: its message was sent again, delayed

delay_seconds: int
message_id: str
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

task_id: str
class celery_cloud.entities.lambda_response.FailedTask(*, task_id: Annotated[str | None, MaxLen(max_length=150)] = None, message_id: str, error: str)[source]

Bases: BaseModel

Representation of a failed Celery task

error: str
message_id: str
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

task_id: str | None
class celery_cloud.entities.lambda_response.LambdaResponse(*, status: str, processed_messages: int | None = None, failed_messages: int | None = None, skipped_messages: int | None = None, delayed_messages: int | None = None, delayed_tasks: list[DelayedTask] | None = None, skipped_tasks: list[SkippedTask] | None = None, processed_tasks: list[ProcessedTask] | None = None, failed_tasks: list[FailedTask] | None = None, batchItemFailures: list[BatchItemFailure] = <factory>, message: str | None = None, details: str | None = None)[source]

Bases: BaseModel

Unified response model for AWS Lambda processing Celery tasks

batchItemFailures: list[BatchItemFailure]
delayed_messages: int | None
delayed_tasks: list[DelayedTask] | None
details: str | None
failed_messages: int | None
failed_tasks: list[FailedTask] | None
message: str | None
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

processed_messages: int | None
processed_tasks: list[ProcessedTask] | None
skipped_messages: int | None
skipped_tasks: list[SkippedTask] | None
status: str
class celery_cloud.entities.lambda_response.ProcessedTask(*, task_id: Annotated[str, MaxLen(max_length=150)], status: str, result: Any | None = None)[source]

Bases: BaseModel

Representation of a successfully processed Celery task

model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

result: Any | None
status: str
task_id: str
class celery_cloud.entities.lambda_response.SkippedTask(*, message_id: str, task_id: Annotated[str, MaxLen(max_length=150)], reason: str)[source]

Bases: BaseModel

A message that was deliberately not executed (duplicate, expired…)

message_id: str
model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

reason: str
task_id: str