dressed_for_succes_store/backend/sync_meilisearch.py

44 lines
1.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
import sys
import os
from pathlib import Path
# Добавляем родительскую директорию в sys.path, чтобы импортировать модули приложения
sys.path.append(str(Path(__file__).parent))
from app.core import SessionLocal
from app.scripts.sync_meilisearch import sync_products, sync_categories, sync_collections, sync_sizes
from app.services import meilisearch_service
def main():
"""
Скрипт для ручной синхронизации данных с Meilisearch.
"""
print("Инициализация индексов Meilisearch...")
meilisearch_service.initialize_indexes()
# Создаем сессию базы данных
db = SessionLocal()
try:
print("Синхронизация категорий...")
sync_categories(db)
print("Синхронизация коллекций...")
sync_collections(db)
print("Синхронизация размеров...")
sync_sizes(db)
print("Синхронизация продуктов...")
sync_products(db)
print("Синхронизация с Meilisearch завершена успешно!")
except Exception as e:
print(f"Ошибка при синхронизации данных с Meilisearch: {str(e)}")
finally:
db.close()
if __name__ == "__main__":
main()