delete_account_task.py 809 B

1234567891011121314151617181920212223242526
  1. import logging
  2. from celery import shared_task # type: ignore
  3. from extensions.ext_database import db
  4. from models.account import Account
  5. from services.billing_service import BillingService
  6. from tasks.mail_account_deletion_task import send_deletion_success_task
  7. logger = logging.getLogger(__name__)
  8. @shared_task(queue="dataset")
  9. def delete_account_task(account_id):
  10. account = db.session.query(Account).filter(Account.id == account_id).first()
  11. try:
  12. BillingService.delete_account(account_id)
  13. except Exception as e:
  14. logger.exception(f"Failed to delete account {account_id} from billing service.")
  15. raise
  16. if not account:
  17. logger.error(f"Account {account_id} not found.")
  18. return
  19. # send success email
  20. send_deletion_success_task.delay(account.email)