d3a9fff0c2
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 46s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m37s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 45s
AI Code Review / AI Code Review (pull_request) Failing after 1m40s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m44s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m50s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 2m28s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 1m47s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m35s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m30s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 4m55s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m37s
CI/CD Pipeline / CI Gate (pull_request) Successful in 8s
CI/CD Pipeline / Production Browser E2E (pull_request) Failing after 578h56m13s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 578h56m14s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 578h56m14s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 578h56m15s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 579h0m24s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 579h0m22s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 579h1m7s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 579h1m7s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 579h1m9s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 579h1m11s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 579h1m11s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 579h30m0s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 579h30m2s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 579h34m11s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 579h34m54s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 579h34m56s
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
"""定期清理任务 — Celery Beat 调度。
|
|
|
|
包含:
|
|
- cleanup_stale_pending_tasks: 定期清理卡在 pending 超时的 generation_tasks
|
|
"""
|
|
|
|
import logging
|
|
|
|
from celery import shared_task
|
|
from worker_app.tasks._startup import (
|
|
PENDING_TASK_TIMEOUT_MINUTES,
|
|
cleanup_stale_pending_tasks,
|
|
)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@shared_task(name="worker.cleanup_stale_pending_tasks")
|
|
def scheduled_cleanup_stale_pending(timeout_minutes: int = PENDING_TASK_TIMEOUT_MINUTES) -> dict:
|
|
"""Celery Beat 调度的定期任务:清理超时的 pending 任务。
|
|
|
|
每 10 分钟执行一次(由 celery_app.py 的 beat_schedule 配置),
|
|
查找所有 status='pending' 且 created_at < NOW() - timeout_minutes
|
|
的 generation_tasks,批量更新为 failed。
|
|
|
|
Args:
|
|
timeout_minutes: 超时时间(分钟),默认 30 分钟
|
|
|
|
Returns:
|
|
{"cleaned": int}
|
|
"""
|
|
count = cleanup_stale_pending_tasks(timeout_minutes)
|
|
if count > 0:
|
|
logger.info("[Beat] 清理了 %d 个超时 pending 任务(超时阈值 %d 分钟)", count, timeout_minutes)
|
|
return {"cleaned": count}
|