40 lines
1.5 KiB
Python
Executable File
40 lines
1.5 KiB
Python
Executable File
# /opt/docker/dev/service_finder/backend/app/services/robot_manager.py
|
|
import asyncio
|
|
import logging
|
|
from datetime import datetime
|
|
from .harvester_cars import VehicleHarvester
|
|
# Megjegyzés: Csak azokat importáld, amik öröklődnek a BaseHarvester-ből
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
class RobotManager:
|
|
@staticmethod
|
|
async def run_full_sync(db):
|
|
""" Sorban lefuttatja a robotokat az új AssetCatalog struktúrához. """
|
|
logger.info(f"🕒 Teljes szinkronizáció indítva: {datetime.now()}")
|
|
|
|
robots = [
|
|
VehicleHarvester(),
|
|
# BikeHarvester(), # Későbbi bővítéshez
|
|
]
|
|
|
|
for robot in robots:
|
|
try:
|
|
# JAVÍTVA: A modern Harvesterek a harvest_all metódust használják
|
|
await robot.harvest_all(db)
|
|
logger.info(f"✅ {robot.category} robot sikeresen lefutott.")
|
|
await asyncio.sleep(5)
|
|
except Exception as e:
|
|
logger.error(f"❌ Kritikus hiba a {robot.category} robotnál: {e}")
|
|
|
|
@staticmethod
|
|
async def schedule_nightly_run(db):
|
|
"""
|
|
LOGIKA MEGŐRIZVE: Éjszakai futtatás 02:00-kor.
|
|
"""
|
|
while True:
|
|
now = datetime.now()
|
|
if now.hour == 2 and now.minute == 0:
|
|
await RobotManager.run_full_sync(db)
|
|
await asyncio.sleep(70) # Megakadályozzuk az újraindulást ugyanabban a percben
|
|
await asyncio.sleep(30) |