Initial monorepo structure
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
"""SMS worker for Celery."""
|
||||
|
||||
from app.workers.celery_app import celery_app
|
||||
from app.core.database import SessionLocal
|
||||
from app.integrations.sms import SMSClient
|
||||
from app.models.ticket import Ticket
|
||||
from app.settings import get_settings
|
||||
|
||||
settings = get_settings()
|
||||
|
||||
|
||||
@celery_app.task(bind=True, max_retries=3)
|
||||
def send_sms_task(self, recipient: str, message: str):
|
||||
"""Send SMS task."""
|
||||
try:
|
||||
sms_client = SMSClient()
|
||||
result = sms_client.send_sms(recipient, message)
|
||||
|
||||
if result["status"] == "error":
|
||||
raise Exception(result["error"])
|
||||
|
||||
return {
|
||||
"status": "success",
|
||||
"recipient": recipient,
|
||||
"message": result
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
raise self.retry(exc=e, countdown=2 ** self.request.retries)
|
||||
|
||||
|
||||
@celery_app.task
|
||||
def send_ticket_created_sms(ticket_id: int, phone_number: str):
|
||||
"""Send SMS notification about ticket creation."""
|
||||
db = SessionLocal()
|
||||
|
||||
try:
|
||||
ticket = db.query(Ticket).filter(Ticket.id == ticket_id).first()
|
||||
if not ticket:
|
||||
return {"status": "error", "message": "Ticket not found"}
|
||||
|
||||
message = f"Тикет #{ticket_id} создан. Приоритет: {ticket.priority.name}, Статус: {ticket.status.name}"
|
||||
|
||||
send_sms_task.delay(phone_number, message)
|
||||
|
||||
return {"status": "success", "ticket_id": ticket_id, "phone": phone_number}
|
||||
|
||||
except Exception as e:
|
||||
return {"status": "error", "error": str(e)}
|
||||
finally:
|
||||
db.close()
|
||||
Reference in New Issue
Block a user