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")
def update_products_task():
def update_products_task() -> tuple[bool, str]:
"""
Run a background task to update product data and manage stale products.
@ -44,7 +44,7 @@ def update_products_task():
vendor = vendor_class()
try:
vendor.update_stock()
except VendorInactiveError as vie:
except VendorInactiveError:
logger.info(f"Skipping {vendor_class} due to inactivity")
except Exception as e:
logger.warning(f"Skipping {vendor_class} due to error: {e!s}")
@ -57,7 +57,7 @@ def update_products_task():
@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
`vendors_classes`. Each vendor class in the `vendors_classes` list is
@ -79,7 +79,7 @@ def update_orderproducts_task():
@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.
@ -95,7 +95,7 @@ def set_default_caches_task():
@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
whose names do not match any UUIDs currently present in the database.

View file

@ -60,7 +60,6 @@ class VendorError(Exception):
class VendorInactiveError(VendorError):
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_OPTIONS = {
"location": (
f"ftp://{getenv('DBBACKUP_USER')}:"
f"{getenv('DBBACKUP_PASS')}@"
f"{getenv('DBBACKUP_HOST')}:21/"
f"{raw_path}"
f"ftp://{getenv('DBBACKUP_USER')}:{getenv('DBBACKUP_PASS')}@{getenv('DBBACKUP_HOST')}:21/{raw_path}"
),
}

View file

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