mirror of
https://github.com/dat515-2025/Group-8.git
synced 2026-03-22 15:12:08 +01:00
feat(infrastructure): update queue worker
This commit is contained in:
29
backend/app/workers/email_handler.py
Normal file
29
backend/app/workers/email_handler.py
Normal 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))
|
||||
Reference in New Issue
Block a user