Templates Migration: - Migrate admin templates to modules (tenancy, billing, monitoring, marketplace, etc.) - Migrate vendor templates to modules (tenancy, billing, orders, messaging, etc.) - Migrate storefront templates to modules (catalog, customers, orders, cart, checkout, cms) - Migrate public templates to modules (billing, marketplace, cms) - Keep shared templates in app/templates/ (base.html, errors/, partials/, macros/) - Migrate letzshop partials to marketplace module Static Files Migration: - Migrate admin JS to modules: tenancy (23 files), core (5 files), monitoring (1 file) - Migrate vendor JS to modules: tenancy (4 files), core (2 files) - Migrate shared JS: vendor-selector.js to core, media-picker.js to cms - Migrate storefront JS: storefront-layout.js to core - Keep framework JS in static/ (api-client, utils, money, icons, log-config, lib/) - Update all template references to use module_static paths Naming Consistency: - Rename static/platform/ to static/public/ - Rename app/templates/platform/ to app/templates/public/ - Update all extends and static references Documentation: - Update module-system.md with shared templates documentation - Update frontend-structure.md with new module JS organization Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
85 lines
2.9 KiB
Python
85 lines
2.9 KiB
Python
# app/modules/marketplace/tasks/sync_tasks.py
|
|
"""
|
|
Celery tasks for Letzshop vendor directory synchronization.
|
|
|
|
Periodically syncs vendor information from Letzshop's public GraphQL API.
|
|
"""
|
|
|
|
import logging
|
|
from typing import Any
|
|
|
|
from app.core.celery_config import celery_app
|
|
from app.modules.task_base import ModuleTask
|
|
from app.modules.messaging.services.admin_notification_service import admin_notification_service
|
|
from app.modules.marketplace.services.letzshop import LetzshopVendorSyncService
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@celery_app.task(
|
|
bind=True,
|
|
base=ModuleTask,
|
|
name="app.modules.marketplace.tasks.sync_tasks.sync_vendor_directory",
|
|
max_retries=2,
|
|
default_retry_delay=300,
|
|
autoretry_for=(Exception,),
|
|
retry_backoff=True,
|
|
)
|
|
def sync_vendor_directory(self) -> dict[str, Any]:
|
|
"""
|
|
Celery task to sync Letzshop vendor directory.
|
|
|
|
Fetches all vendors from Letzshop's public GraphQL API and updates
|
|
the local letzshop_vendor_cache table.
|
|
|
|
This task is scheduled to run daily via the module's scheduled_tasks
|
|
definition.
|
|
|
|
Returns:
|
|
dict: Sync statistics including created, updated, and error counts.
|
|
"""
|
|
with self.get_db() as db:
|
|
try:
|
|
logger.info("Starting Letzshop vendor directory sync...")
|
|
|
|
sync_service = LetzshopVendorSyncService(db)
|
|
|
|
def progress_callback(page: int, fetched: int, total: int):
|
|
"""Log progress during sync."""
|
|
logger.info(f"Vendor sync progress: page {page}, {fetched}/{total} vendors")
|
|
|
|
stats = sync_service.sync_all_vendors(progress_callback=progress_callback)
|
|
|
|
logger.info(
|
|
f"Vendor directory sync completed: "
|
|
f"{stats.get('created', 0)} created, "
|
|
f"{stats.get('updated', 0)} updated, "
|
|
f"{stats.get('errors', 0)} errors"
|
|
)
|
|
|
|
# Send admin notification if there were errors
|
|
if stats.get("errors", 0) > 0:
|
|
admin_notification_service.notify_system_info(
|
|
db=db,
|
|
title="Letzshop Vendor Sync Completed with Errors",
|
|
message=(
|
|
f"Synced {stats.get('total_fetched', 0)} vendors. "
|
|
f"Errors: {stats.get('errors', 0)}"
|
|
),
|
|
details=stats,
|
|
)
|
|
|
|
return stats
|
|
|
|
except Exception as e:
|
|
logger.error(f"Vendor directory sync failed: {e}", exc_info=True)
|
|
|
|
# Notify admins of failure
|
|
admin_notification_service.notify_critical_error(
|
|
db=db,
|
|
error_type="Vendor Directory Sync",
|
|
error_message=f"Failed to sync Letzshop vendor directory: {str(e)[:200]}",
|
|
details={"error": str(e)},
|
|
)
|
|
raise # Re-raise for Celery retry
|