Features: 1) Add logging for transaction processing errors in payments/signals.py; 2) Add return type annotations for core tasks in core/tasks.py;

Fixes: 1) Avoid unused variable warning in `update_products_task` by removing exception variable `vie`; 2) Add missing imports for `logging` and `traceback` in `payments/signals.py`;

Extra: 1) Minor formatting fix in `dbbackup.py` to consolidate FTP URL string construction; 2) Remove unnecessary newline in `core/vendors/__init__.py`.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-08-11 14:05:48 +03:00
parent 8c2fbc1e44
commit 59870b3bc5
4 changed files with 12 additions and 10 deletions

View file

@ -20,7 +20,7 @@ logger = get_task_logger(__name__)
@shared_task(queue="stock_updater") @shared_task(queue="stock_updater")
def update_products_task(): def update_products_task() -> tuple[bool, str]:
""" """
Run a background task to update product data and manage stale products. Run a background task to update product data and manage stale products.
@ -44,7 +44,7 @@ def update_products_task():
vendor = vendor_class() vendor = vendor_class()
try: try:
vendor.update_stock() vendor.update_stock()
except VendorInactiveError as vie: except VendorInactiveError:
logger.info(f"Skipping {vendor_class} due to inactivity") logger.info(f"Skipping {vendor_class} due to inactivity")
except Exception as e: except Exception as e:
logger.warning(f"Skipping {vendor_class} due to error: {e!s}") logger.warning(f"Skipping {vendor_class} due to error: {e!s}")
@ -57,7 +57,7 @@ def update_products_task():
@shared_task(queue="default") @shared_task(queue="default")
def update_orderproducts_task(): def update_orderproducts_task() -> tuple[bool, str]:
""" """
Updates the statuses of order products for all vendors listed in the Updates the statuses of order products for all vendors listed in the
`vendors_classes`. Each vendor class in the `vendors_classes` list is `vendors_classes`. Each vendor class in the `vendors_classes` list is
@ -79,7 +79,7 @@ def update_orderproducts_task():
@shared_task(queue="default") @shared_task(queue="default")
def set_default_caches_task(): def set_default_caches_task() -> tuple[bool, str]:
""" """
Task to set default caches in the application's memory. Task to set default caches in the application's memory.
@ -95,7 +95,7 @@ def set_default_caches_task():
@shared_task(queue="default") @shared_task(queue="default")
def remove_stale_product_images(): def remove_stale_product_images() -> tuple[bool, str]:
""" """
Removes stale product images from the products directory by identifying directories Removes stale product images from the products directory by identifying directories
whose names do not match any UUIDs currently present in the database. whose names do not match any UUIDs currently present in the database.

View file

@ -60,7 +60,6 @@ class VendorError(Exception):
class VendorInactiveError(VendorError): class VendorInactiveError(VendorError):
pass pass

View file

@ -38,10 +38,7 @@ if getenv("DBBACKUP_HOST") and getenv("DBBACKUP_USER") and getenv("DBBACKUP_PASS
DBBACKUP_STORAGE = "evibes.ftpstorage.AbsoluteFTPStorage" DBBACKUP_STORAGE = "evibes.ftpstorage.AbsoluteFTPStorage"
DBBACKUP_STORAGE_OPTIONS = { DBBACKUP_STORAGE_OPTIONS = {
"location": ( "location": (
f"ftp://{getenv('DBBACKUP_USER')}:" f"ftp://{getenv('DBBACKUP_USER')}:{getenv('DBBACKUP_PASS')}@{getenv('DBBACKUP_HOST')}:21/{raw_path}"
f"{getenv('DBBACKUP_PASS')}@"
f"{getenv('DBBACKUP_HOST')}:21/"
f"{raw_path}"
), ),
} }

View file

@ -1,3 +1,6 @@
import logging
import traceback
from django.db.models.signals import post_save from django.db.models.signals import post_save
from django.dispatch import receiver from django.dispatch import receiver
@ -6,6 +9,8 @@ from payments.models import Balance, Transaction
from payments.utils.emailing import balance_deposit_email from payments.utils.emailing import balance_deposit_email
from vibes_auth.models import User from vibes_auth.models import User
logger = logging.getLogger("django")
@receiver(post_save, sender=User) @receiver(post_save, sender=User)
def create_balance_on_user_creation_signal(instance, created, **_kwargs): def create_balance_on_user_creation_signal(instance, created, **_kwargs):
@ -27,6 +32,7 @@ def process_transaction_changes(instance, created, **_kwargs):
gateway.process_transaction(instance) gateway.process_transaction(instance)
except Exception as e: except Exception as e:
instance.process = {"status": "ERRORED", "error": str(e)} instance.process = {"status": "ERRORED", "error": str(e)}
logger.error(f"Error processing transaction {instance.uuid}: {e}\n{traceback.format_exc()}")
if not created: if not created:
status = str(instance.process.get("status", "")).lower() status = str(instance.process.get("status", "")).lower()
success = instance.process.get("success", False) success = instance.process.get("success", False)