feat(infrastructure): update queue worker

This commit is contained in:
2025-10-02 13:00:57 +02:00
parent 42f3d4dae1
commit 6d8b760a7d
5 changed files with 232 additions and 57 deletions

View File

@@ -0,0 +1,29 @@
import asyncio
from typing import Any, Dict
# Import decorator and logger from the worker so handlers can register themselves
from .queue_worker import register_task_handler, logger
@register_task_handler("email")
async def handle_email_task(payload: Dict[str, Any]) -> None:
"""Handle 'email' tasks dispatched by the queue worker.
Expected payload schema:
{
"type": "email",
"to": "recipient@example.com",
"subject": "Subject text",
"body": "Email body text"
}
"""
to = payload.get("to")
subject = payload.get("subject")
body = payload.get("body")
if not (to and subject and body):
logger.error("Email task missing fields. Payload: %s", payload)
return
# Placeholder for real email sending logic
await asyncio.sleep(0) # yield control, simulate async work
logger.info("Email sent | to=%s | subject=%s | body_len=%d", to, subject, len(body))