From 504d87b0b066921437c44ec901be99a5b73071f7 Mon Sep 17 00:00:00 2001 From: Ke Sun Date: Fri, 30 Jan 2026 12:14:39 +0800 Subject: [PATCH] feat(tasks): add celery task configuration for periodic jobs - Add ignore_result=True to prevent storing results for periodic tasks - Set max_retries=0 to skip failed periodic tasks without retry attempts - Configure acks_late=False for immediate acknowledgment in beat tasks - Add time_limit and soft_time_limit to regenerate_memory_cache task (3600s/3300s) - Add time_limit and soft_time_limit to workspace_reflection_task (300s/240s) - Add time_limit and soft_time_limit to run_forgetting_cycle_task (7200s/7000s) - Improve task reliability and resource management for scheduled jobs --- api/app/tasks.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/api/app/tasks.py b/api/app/tasks.py index cdd7945e..48b41e4f 100644 --- a/api/app/tasks.py +++ b/api/app/tasks.py @@ -774,7 +774,15 @@ def write_total_memory_task(workspace_id: str) -> Dict[str, Any]: } -@celery_app.task(name="app.tasks.regenerate_memory_cache", bind=True) +@celery_app.task( + name="app.tasks.regenerate_memory_cache", + bind=True, + ignore_result=True, + max_retries=0, + acks_late=False, + time_limit=3600, + soft_time_limit=3300, +) def regenerate_memory_cache(self) -> Dict[str, Any]: """定时任务:为所有用户重新生成记忆洞察和用户摘要缓存 @@ -966,7 +974,16 @@ def regenerate_memory_cache(self) -> Dict[str, Any]: } -@celery_app.task(name="app.tasks.workspace_reflection_task", bind=True) + +@celery_app.task( + name="app.tasks.workspace_reflection_task", + bind=True, + ignore_result=True, + max_retries=0, + acks_late=False, + time_limit=300, + soft_time_limit=240, +) def workspace_reflection_task(self) -> Dict[str, Any]: """定时任务:每30秒运行工作空间反思功能 @@ -1111,7 +1128,16 @@ def workspace_reflection_task(self) -> Dict[str, Any]: -@celery_app.task(name="app.tasks.run_forgetting_cycle_task", bind=True) + +@celery_app.task( + name="app.tasks.run_forgetting_cycle_task", + bind=True, + ignore_result=True, + max_retries=0, + acks_late=False, + time_limit=7200, + soft_time_limit=7000, +) def run_forgetting_cycle_task(self, config_id: Optional[uuid.UUID] = None) -> Dict[str, Any]: """定时任务:运行遗忘周期