Files
service-finder/backend/app/workers/service_auditor.py

42 lines
1.6 KiB
Python

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)