feat: enhance Letzshop jobs and order management
- Add job cancellation and retry functionality - Improve jobs table with better status display - Add background task improvements - Update Letzshop order service - Update documentation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import logging
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from app.core.database import SessionLocal
|
||||
from app.services.admin_notification_service import admin_notification_service
|
||||
from app.utils.csv_processor import CSVProcessor
|
||||
from models.database.marketplace_import_job import MarketplaceImportJob
|
||||
from models.database.vendor import Vendor
|
||||
@@ -88,6 +89,16 @@ async def process_marketplace_import(
|
||||
job.status = "completed_with_errors"
|
||||
job.error_message = f"{result['errors']} rows had errors"
|
||||
|
||||
# Notify admin if error count is significant
|
||||
if result.get("errors", 0) >= 5:
|
||||
admin_notification_service.notify_import_failure(
|
||||
db=db,
|
||||
vendor_name=vendor.name,
|
||||
job_id=job_id,
|
||||
error_message=f"Import completed with {result['errors']} errors out of {result['total_processed']} rows",
|
||||
vendor_id=vendor_id,
|
||||
)
|
||||
|
||||
db.commit()
|
||||
logger.info(
|
||||
f"Import job {job_id} completed: "
|
||||
@@ -102,6 +113,17 @@ async def process_marketplace_import(
|
||||
job.status = "failed"
|
||||
job.error_message = str(e)
|
||||
job.completed_at = datetime.now(UTC)
|
||||
|
||||
# Create admin notification for import failure
|
||||
vendor_name = vendor.name if vendor else f"Vendor {vendor_id}"
|
||||
admin_notification_service.notify_import_failure(
|
||||
db=db,
|
||||
vendor_name=vendor_name,
|
||||
job_id=job_id,
|
||||
error_message=str(e)[:200], # Truncate long errors
|
||||
vendor_id=vendor_id,
|
||||
)
|
||||
|
||||
db.commit()
|
||||
except Exception as commit_error:
|
||||
logger.error(f"Failed to update job status: {commit_error}")
|
||||
|
||||
@@ -6,6 +6,7 @@ from datetime import UTC, datetime
|
||||
from typing import Callable
|
||||
|
||||
from app.core.database import SessionLocal
|
||||
from app.services.admin_notification_service import admin_notification_service
|
||||
from app.services.letzshop import LetzshopClientError
|
||||
from app.services.letzshop.credentials_service import LetzshopCredentialsService
|
||||
from app.services.letzshop.order_service import LetzshopOrderService
|
||||
@@ -207,6 +208,20 @@ def process_historical_import(job_id: int, vendor_id: int):
|
||||
job.status = "failed"
|
||||
job.error_message = f"Letzshop API error: {e}"
|
||||
job.completed_at = datetime.now(UTC)
|
||||
|
||||
# Get vendor name for notification
|
||||
order_service = _get_order_service(db)
|
||||
vendor = order_service.get_vendor(vendor_id)
|
||||
vendor_name = vendor.name if vendor else f"Vendor {vendor_id}"
|
||||
|
||||
# Create admin notification for sync failure
|
||||
admin_notification_service.notify_order_sync_failure(
|
||||
db=db,
|
||||
vendor_name=vendor_name,
|
||||
error_message=f"Historical import failed: {str(e)[:150]}",
|
||||
vendor_id=vendor_id,
|
||||
)
|
||||
|
||||
db.commit()
|
||||
|
||||
creds_service = _get_credentials_service(db)
|
||||
@@ -222,6 +237,20 @@ def process_historical_import(job_id: int, vendor_id: int):
|
||||
job.status = "failed"
|
||||
job.error_message = str(e)
|
||||
job.completed_at = datetime.now(UTC)
|
||||
|
||||
# Get vendor name for notification
|
||||
order_service = _get_order_service(db)
|
||||
vendor = order_service.get_vendor(vendor_id)
|
||||
vendor_name = vendor.name if vendor else f"Vendor {vendor_id}"
|
||||
|
||||
# Create admin notification for critical error
|
||||
admin_notification_service.notify_critical_error(
|
||||
db=db,
|
||||
error_type="Historical Import",
|
||||
error_message=f"Import job {job_id} failed for {vendor_name}: {str(e)[:150]}",
|
||||
details={"job_id": job_id, "vendor_id": vendor_id, "vendor_name": vendor_name},
|
||||
)
|
||||
|
||||
db.commit()
|
||||
except Exception as commit_error:
|
||||
logger.error(f"Job {job_id}: Failed to update job status: {commit_error}")
|
||||
|
||||
Reference in New Issue
Block a user