feat(robot): hunter v2.7, geocoding support, docker network fix, changelog update
This commit is contained in:
42
backend/app/workers/service_auditor.py
Normal file
42
backend/app/workers/service_auditor.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import asyncio
|
||||
import logging
|
||||
from app.db.session import SessionLocal
|
||||
from app.models.organization import Organization
|
||||
from app.models.service import ServiceProfile
|
||||
from sqlalchemy import select, and_
|
||||
|
||||
logger = logging.getLogger("Robot2-Auditor")
|
||||
|
||||
class ServiceAuditor:
|
||||
@classmethod
|
||||
async def audit_services(cls):
|
||||
"""Időszakos ellenőrzés a megszűnt helyek kiszűrésére."""
|
||||
async with SessionLocal() as db:
|
||||
# Csak az aktív szervizeket nézzük
|
||||
stmt = select(Organization).where(
|
||||
and_(Organization.org_type == "service", Organization.is_active == True)
|
||||
)
|
||||
result = await db.execute(stmt)
|
||||
services = result.scalars().all()
|
||||
|
||||
for service in services:
|
||||
# 1. Ellenőrzés külső forrásnál (API hívás helye)
|
||||
# status = await check_external_status(service.full_name)
|
||||
is_still_open = True # Itt jön az OSM/Google API válasza
|
||||
|
||||
if not is_still_open:
|
||||
service.is_active = False # SOFT-DELETE
|
||||
logger.info(f"⚠️ Szerviz inaktiválva (megszűnt): {service.full_name}")
|
||||
|
||||
# Rate limit védelem
|
||||
await asyncio.sleep(2)
|
||||
|
||||
await db.commit()
|
||||
|
||||
@classmethod
|
||||
async def run_periodic_audit(cls):
|
||||
while True:
|
||||
logger.info("🕵️ Negyedéves szerviz-audit indítása...")
|
||||
await cls.audit_services()
|
||||
# 90 naponta fusson le teljes körűen
|
||||
await asyncio.sleep(90 * 86400)
|
||||
Reference in New Issue
Block a user