from __future__ import annotations from celery import shared_task @shared_task(name="govoplan_calendar.sync_due_caldav_sources") def sync_due_caldav_sources_task(tenant_id: str | None = None, limit: int = 50) -> list[dict[str, object]]: from govoplan_calendar.backend.service import sync_due_sources from govoplan_core.db.session import get_database with get_database().SessionLocal() as session: results = sync_due_sources(session, tenant_id=tenant_id, limit=limit) session.commit() return [ { "source_id": item.source_id, "calendar_id": item.calendar_id, "status": item.status, "error": item.error, "created": item.stats.created if item.stats else 0, "updated": item.stats.updated if item.stats else 0, "deleted": item.stats.deleted if item.stats else 0, "unchanged": item.stats.unchanged if item.stats else 0, "fetched": item.stats.fetched if item.stats else 0, } for item in results ]