Messaging
How the runner sends Celery messages to SQS: delayed tasks, retries and the next tasks of a workflow.
Send Celery messages to SQS from the runner.
The runner needs to publish messages in three cases: to hold a task until its eta
(it sends the same message back with a delay), to retry a task (same message with an
updated retries/eta header) and to start the next task of a canvas (a message
built from a signature). Messages follow Celery’s protocol 2, the format that the
Celery client (kombu) writes: base64(json(envelope)) with the body, headers and
properties, where the envelope body is base64(json([args, kwargs, embed])).
- class celery_cloud.messaging.QueueRef(partition: str, region: str, account: str, name: str)[source]
Bases:
NamedTupleAn SQS queue, as found in the
eventSourceARNof a record.
- celery_cloud.messaging.build_message(signature: dict[str, Any], args_prefix: Sequence[Any] = (), *, queue: str, parent_id: str | None = None, root_id: str | None = None, chain: list[dict[str, Any]] | None = None, now: datetime | None = None) tuple[str, str][source]
Build the message that runs a Celery signature (as a client would send it).
- Parameters:
signature – A signature dict (
task,args,kwargs,options,immutable), the format Celery puts inlink,chainandchord.args_prefix – Arguments placed before the signature’s own (the result of the previous task). Ignored when the signature is immutable.
queue – Name of the queue the message is for (its routing key).
parent_id – Id of the task that triggers this one.
root_id – Id of the first task of the workflow.
chain – Remaining steps of a chain to carry in the message.
now – Clock, for tests.
- Returns:
(task_id, sqs_message_body).
- celery_cloud.messaging.delay_message(record: SQSRecord, seconds: float) int[source]
Send the message of
recordback to its queue, delayed. Returns the delay.
- celery_cloud.messaging.encode_body(envelope: dict[str, Any]) str[source]
The SQS message body kombu writes for a Celery message envelope.