Handle errors in vendor stock updates and inactive vendors
Add error handling during the stock update process to log and skip problematic vendors without halting execution. Additionally, ensure `get_vendor_instance` only returns active vendors, raising an error if the vendor is inactive. This improves system resilience and data integrity.
This commit is contained in:
parent
6e19d9f65f
commit
87e124f614
2 changed files with 8 additions and 2 deletions
|
|
@ -42,7 +42,10 @@ def update_products_task():
|
||||||
|
|
||||||
for vendor_class in vendors_classes:
|
for vendor_class in vendors_classes:
|
||||||
vendor = vendor_class()
|
vendor = vendor_class()
|
||||||
vendor.update_stock()
|
try:
|
||||||
|
vendor.update_stock()
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"Skipping {vendor_class} due to error: {e!s}")
|
||||||
|
|
||||||
delete_stale()
|
delete_stale()
|
||||||
|
|
||||||
|
|
|
||||||
5
core/vendors/__init__.py
vendored
5
core/vendors/__init__.py
vendored
|
|
@ -148,7 +148,10 @@ class AbstractVendor:
|
||||||
|
|
||||||
def get_vendor_instance(self):
|
def get_vendor_instance(self):
|
||||||
try:
|
try:
|
||||||
return Vendor.objects.get(name=self.vendor_name)
|
vendor = Vendor.objects.get(name=self.vendor_name)
|
||||||
|
if vendor.is_active:
|
||||||
|
return vendor
|
||||||
|
raise VendorError(f"Vendor {self.vendor_name!r} is inactive...")
|
||||||
except Vendor.DoesNotExist:
|
except Vendor.DoesNotExist:
|
||||||
raise Exception(f"No matching vendor found with name {self.vendor_name!r}...")
|
raise Exception(f"No matching vendor found with name {self.vendor_name!r}...")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue