mirror of
https://github.com/dat515-2025/Group-8.git
synced 2026-03-22 06:57:47 +01:00
30 lines
944 B
Python
30 lines
944 B
Python
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))
|