From 6418b1469db37664f37606bb66def51248060091 Mon Sep 17 00:00:00 2001 From: i701 Date: Wed, 9 Jul 2025 20:32:04 +0500 Subject: [PATCH] =?UTF-8?q?refactor(tasks):=20replace=20Enum=20with=20stri?= =?UTF-8?q?ng=20literals=20for=20notification=20types=20in=20SMS=20tasks?= =?UTF-8?q?=20=F0=9F=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- billing/tasks.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/billing/tasks.py b/billing/tasks.py index 1a2e790..56977d3 100644 --- a/billing/tasks.py +++ b/billing/tasks.py @@ -7,16 +7,10 @@ from api.notifications import send_sms from billing.models import Topup, Payment from django.utils.timezone import localtime from datetime import datetime -from enum import Enum logger = logging.getLogger(__name__) -class NotificationType(Enum): - TOPUP = "TOPUP" - PAYMENT = "PAYMENT" - - @app.periodic( cron="*/1 * * * * *", periodic_id="notify_expired_topups", queue="heavy_tasks" ) @@ -39,7 +33,7 @@ def update_expired_topups(timestamp: int): if topup.user and topup.user.mobile and not topup.expiry_notification_sent: send_sms_task.defer( mobile=topup.user.mobile, - type=NotificationType.TOPUP, + type="TOPUP", amount=topup.amount, model_id=str(topup.id), created_at=localtime(topup.created_at).isoformat(), @@ -85,7 +79,7 @@ def update_expired_payments(timestamp: int): ): send_sms_task.defer( mobile=payment.user.mobile, - type=NotificationType.PAYMENT, + type="PAYMENT", amount=payment.amount, model_id=str(payment.id), created_at=localtime(payment.created_at).isoformat(), @@ -112,7 +106,7 @@ def send_sms_task( amount: float, model_id: str, created_at: str, - type: NotificationType = NotificationType.TOPUP, + type: str = "TOPUP", # Default to TOPUP if not provided, ): try: dt = datetime.fromisoformat(created_at) @@ -120,17 +114,17 @@ def send_sms_task( except Exception: formatted_date = created_at message: str = "" - if type == NotificationType.TOPUP: + if type == "TOPUP": message = ( f"Dear {user}, \n\nYour topup of {amount} MVR [created at {formatted_date}] has expired. " "Please make a new topup to update your wallet. \n\n- SAR Link" ) - elif type == NotificationType.PAYMENT: + elif type == "PAYMENT": message = f"Dear {user}, \n\nYour payment of {amount} MVR [created at {formatted_date}] has expired. \n\n- SAR Link" send_sms(mobile, message) - logger.info(f"SMS sent to {mobile} for expired {type.value} of {amount} MVR.") + logger.info(f"SMS sent to {mobile} for expired {type} of {amount} MVR.") - if type == NotificationType.TOPUP: + if type == "TOPUP": try: topup = Topup.objects.get(id=model_id) topup.expiry_notification_sent = True