"""Scheduled-job handler for Feishu helpdesk ticket sync. ``feishu.helpdesk_sync`` mirrors every enabled ``helpdesk``/``feishu`` integration's tickets into ``feishu_helpdesk_tickets`` for analytics. The DB row (seeded by migration 314) runs it on a 12-hour interval. The work is idempotent (upsert keyed on ``ticket_id``), so a re-run / overlapping window is safe. """ from __future__ import annotations from typing import Any from sqlalchemy.ext.asyncio import AsyncSession from app.domains.feishu_helpdesk.sync import sync_all_helpdesks from app.scheduled_jobs.registry import register_scheduled_job @register_scheduled_job( key="feishu.helpdesk_sync", display_name="飞书 · 服务台工单同步", description=( "增量拉取飞书服务台(Helpdesk)工单到本地镜像表,供服务台分析报表使用。" "每 12 小时一次,按 update_time 增量,upsert 幂等。" ), ) async def run_feishu_helpdesk_sync( db: AsyncSession, config: dict[str, Any], # noqa: ARG001 ) -> dict[str, Any]: return await sync_all_helpdesks(db)