Features:

1) Add Celery shared_task decorator to `update_stock` method for asynchronous execution.

Fixes:
1) Replace direct `update_stock()` calls with `update_stock.delay()` to enable task queuing.

Extra:
1) Add missing import for `shared_task` in `core/vendors/__init__.py`.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-05-09 04:29:07 +03:00
parent 60240d4cd9
commit a31ce44dfc
2 changed files with 4 additions and 1 deletions

View file

@ -43,7 +43,7 @@ def update_products_task():
for vendor_class in vendors_classes:
vendor = vendor_class()
try:
vendor.update_stock()
vendor.update_stock.delay()
except Exception as e:
logger.warning(f"Skipping {vendor_class} due to error: {e!s}")

View file

@ -2,6 +2,8 @@ import json
from contextlib import suppress
from math import ceil
from celery import shared_task
from core.elasticsearch import process_query
from core.models import AttributeValue, Brand, Category, Product, Stock, Vendor
from payments.errors import RatesError
@ -204,6 +206,7 @@ class AbstractVendor:
self.get_stocks_queryset().delete()
self.get_attribute_values_queryset().delete()
@shared_task
def update_stock(self):
pass