| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- """账号文章抓取 XXL-JOB Handler —— accounts(gh_id) → 文章列表 API → articles 表
- XXL-JOB Admin 配置:
- 执行器: long-articles-agentic-src
- 处理器: accountArticleFetch
- 超时: 建议 ≥1800s(深翻翻页多,单个账号可能需要几十页)
- """
- import logging
- from src.infra.xxl_jobs import xxl_job
- from src.domains.content_supply import AccountArticleFetch, ContentSupplyConst
- from src.handlers._utils import get_db, parse_limit
- from src.handlers._logging import get_task_logger
- logger = logging.getLogger(__name__)
- @xxl_job("accountArticleFetch")
- async def account_article_fetch(param: str) -> dict:
- limit = parse_limit(param, ContentSupplyConst.ARTICLE_DEAL_LIMIT)
- tlog = get_task_logger("accountArticleFetch")
- await tlog.task_started(limit=limit)
- try:
- mysql = get_db().mysql_manager("long_articles")
- fetcher = AccountArticleFetch(mysql, task_logger=tlog)
- result = await fetcher.deal(limit=limit)
- except Exception as e:
- logger.exception("账号文章抓取失败")
- await tlog.task_failed(e)
- return {"code": 500, "msg": "账号文章抓取异常"}
- logger.info(
- "accountArticleFetch done: accounts=%d, articles_written=%d, errors=%d",
- result["accounts"],
- result["articles_written"],
- result["errors"],
- )
- await tlog.task_completed(**result)
- return {
- "code": 200,
- "msg": f"accounts={result['accounts']}, written={result['articles_written']}, errors={result['errors']}",
- }
|