account_article_fetch.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. """账号文章抓取 XXL-JOB Handler —— accounts(gh_id) → 文章列表 API → articles 表
  2. XXL-JOB Admin 配置:
  3. 执行器: long-articles-agentic-src
  4. 处理器: accountArticleFetch
  5. 超时: 建议 ≥1800s(深翻翻页多,单个账号可能需要几十页)
  6. """
  7. import logging
  8. from src.infra.xxl_jobs import xxl_job
  9. from src.domains.content_supply import AccountArticleFetch, ContentSupplyConst
  10. from src.handlers._utils import get_db, parse_limit
  11. from src.handlers._logging import get_task_logger
  12. logger = logging.getLogger(__name__)
  13. @xxl_job("accountArticleFetch")
  14. async def account_article_fetch(param: str) -> dict:
  15. limit = parse_limit(param, ContentSupplyConst.ARTICLE_DEAL_LIMIT)
  16. tlog = get_task_logger("accountArticleFetch")
  17. await tlog.task_started(limit=limit)
  18. try:
  19. mysql = get_db().mysql_manager("long_articles")
  20. fetcher = AccountArticleFetch(mysql, task_logger=tlog)
  21. result = await fetcher.deal(limit=limit)
  22. except Exception as e:
  23. logger.exception("账号文章抓取失败")
  24. await tlog.task_failed(e)
  25. return {"code": 500, "msg": "账号文章抓取异常"}
  26. logger.info(
  27. "accountArticleFetch done: accounts=%d, articles_written=%d, errors=%d",
  28. result["accounts"],
  29. result["articles_written"],
  30. result["errors"],
  31. )
  32. await tlog.task_completed(**result)
  33. return {
  34. "code": 200,
  35. "msg": f"accounts={result['accounts']}, written={result['articles_written']}, errors={result['errors']}",
  36. }