```
feat: 添加生命周期报告和AI规则管理功能 - 在Dockerfile中添加pillow依赖包用于图像处理 - 实现生命周期报告调度任务,支持日报和周报两种类型 - 新增TASK_RUN_LIFECYCLE任务常量和相关配置选项 - 扩展AI Agent服务以支持用户规则,并在分析时应用规则 - 添加AI用户规则创建、更新和查询接口 - 增加项目生命周期和财务需求分析技能 - 扩展现有模型以支持更完整的业务数据字段 - 实现飞书图片上传功能用于报告展示 ```
This commit is contained in:
@@ -38,6 +38,7 @@ def create_scheduler(app: FastAPI | None = None) -> Any:
|
||||
enqueue_event_dispatch,
|
||||
enqueue_legacy_project_sync,
|
||||
enqueue_legacy_task_sync,
|
||||
enqueue_lifecycle_report,
|
||||
enqueue_project_weekly_push,
|
||||
)
|
||||
from app.modules.observability.service import ObservabilityService
|
||||
@@ -108,6 +109,24 @@ def create_scheduler(app: FastAPI | None = None) -> Any:
|
||||
dispatch = enqueue_legacy_task_sync(actor=ActorValue.SCHEDULER)
|
||||
_set_state(app, "last_legacy_task_sync_dispatch", dispatch)
|
||||
|
||||
def run_daily_lifecycle() -> None:
|
||||
dispatch = enqueue_lifecycle_report(
|
||||
report_type="daily",
|
||||
receive_id=settings.feishu_default_chat_id,
|
||||
receive_id_type=FeishuReceiveIdType.CHAT_ID,
|
||||
actor=ActorValue.SCHEDULER,
|
||||
)
|
||||
_set_state(app, "last_daily_lifecycle_dispatch", dispatch)
|
||||
|
||||
def run_weekly_lifecycle() -> None:
|
||||
dispatch = enqueue_lifecycle_report(
|
||||
report_type="weekly",
|
||||
receive_id=settings.feishu_default_chat_id,
|
||||
receive_id_type=FeishuReceiveIdType.CHAT_ID,
|
||||
actor=ActorValue.SCHEDULER,
|
||||
)
|
||||
_set_state(app, "last_weekly_lifecycle_dispatch", dispatch)
|
||||
|
||||
def run_event_dispatch() -> None:
|
||||
dispatch = enqueue_event_dispatch(
|
||||
limit=settings.event_dispatch_batch_size,
|
||||
@@ -127,23 +146,42 @@ def create_scheduler(app: FastAPI | None = None) -> Any:
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
scheduler.add_job(
|
||||
run_daily_brief,
|
||||
trigger="cron",
|
||||
hour=settings.daily_brief_cron_hour,
|
||||
minute=settings.daily_brief_cron_minute,
|
||||
id="daily_brief_push",
|
||||
replace_existing=True,
|
||||
)
|
||||
scheduler.add_job(
|
||||
run_project_weekly,
|
||||
trigger="cron",
|
||||
day_of_week=settings.weekly_project_report_day_of_week,
|
||||
hour=settings.weekly_project_report_cron_hour,
|
||||
minute=settings.weekly_project_report_cron_minute,
|
||||
id="project_weekly_push",
|
||||
replace_existing=True,
|
||||
)
|
||||
if settings.lifecycle_pipeline_enabled:
|
||||
scheduler.add_job(
|
||||
run_daily_lifecycle,
|
||||
trigger="cron",
|
||||
hour=settings.daily_brief_cron_hour,
|
||||
minute=settings.daily_brief_cron_minute,
|
||||
id="daily_lifecycle_pipeline",
|
||||
replace_existing=True,
|
||||
)
|
||||
scheduler.add_job(
|
||||
run_weekly_lifecycle,
|
||||
trigger="cron",
|
||||
day_of_week=settings.weekly_project_report_day_of_week,
|
||||
hour=settings.weekly_project_report_cron_hour,
|
||||
minute=settings.weekly_project_report_cron_minute,
|
||||
id="weekly_lifecycle_pipeline",
|
||||
replace_existing=True,
|
||||
)
|
||||
else:
|
||||
scheduler.add_job(
|
||||
run_daily_brief,
|
||||
trigger="cron",
|
||||
hour=settings.daily_brief_cron_hour,
|
||||
minute=settings.daily_brief_cron_minute,
|
||||
id="daily_brief_push",
|
||||
replace_existing=True,
|
||||
)
|
||||
scheduler.add_job(
|
||||
run_project_weekly,
|
||||
trigger="cron",
|
||||
day_of_week=settings.weekly_project_report_day_of_week,
|
||||
hour=settings.weekly_project_report_cron_hour,
|
||||
minute=settings.weekly_project_report_cron_minute,
|
||||
id="project_weekly_push",
|
||||
replace_existing=True,
|
||||
)
|
||||
if settings.event_dispatch_enabled:
|
||||
scheduler.add_job(
|
||||
run_event_dispatch,
|
||||
@@ -159,7 +197,11 @@ def create_scheduler(app: FastAPI | None = None) -> Any:
|
||||
id="scheduler_heartbeat",
|
||||
replace_existing=True,
|
||||
)
|
||||
if settings.legacy_sync_enabled and settings.legacy_project_query:
|
||||
if (
|
||||
not settings.lifecycle_pipeline_enabled
|
||||
and settings.legacy_sync_enabled
|
||||
and settings.legacy_project_query
|
||||
):
|
||||
scheduler.add_job(
|
||||
run_legacy_project_sync,
|
||||
trigger="cron",
|
||||
@@ -168,7 +210,11 @@ def create_scheduler(app: FastAPI | None = None) -> Any:
|
||||
id="legacy_project_sync",
|
||||
replace_existing=True,
|
||||
)
|
||||
if settings.legacy_sync_enabled and settings.legacy_task_query:
|
||||
if (
|
||||
not settings.lifecycle_pipeline_enabled
|
||||
and settings.legacy_sync_enabled
|
||||
and settings.legacy_task_query
|
||||
):
|
||||
scheduler.add_job(
|
||||
run_legacy_task_sync,
|
||||
trigger="cron",
|
||||
|
||||
@@ -5,10 +5,12 @@ from app.core.background.task_queue.constants import (
|
||||
TASK_PUSH_PROJECT_WEEKLY,
|
||||
TASK_SYNC_LEGACY_PROJECTS,
|
||||
TASK_SYNC_LEGACY_TASKS,
|
||||
TASK_RUN_LIFECYCLE,
|
||||
)
|
||||
from app.core.background.task_queue.dispatcher import dispatch_task
|
||||
from app.core.background.task_queue.events import enqueue_event_dispatch
|
||||
from app.core.background.task_queue.legacy import enqueue_legacy_project_sync, enqueue_legacy_task_sync
|
||||
from app.core.background.task_queue.lifecycle import enqueue_lifecycle_report
|
||||
from app.core.background.task_queue.reports import enqueue_daily_brief_push, enqueue_project_weekly_push
|
||||
from app.core.background.task_queue.risk import enqueue_risk_event_generation
|
||||
|
||||
@@ -20,11 +22,13 @@ __all__ = [
|
||||
"TASK_PUSH_PROJECT_WEEKLY",
|
||||
"TASK_SYNC_LEGACY_PROJECTS",
|
||||
"TASK_SYNC_LEGACY_TASKS",
|
||||
"TASK_RUN_LIFECYCLE",
|
||||
"dispatch_task",
|
||||
"enqueue_daily_brief_push",
|
||||
"enqueue_event_dispatch",
|
||||
"enqueue_legacy_project_sync",
|
||||
"enqueue_legacy_task_sync",
|
||||
"enqueue_lifecycle_report",
|
||||
"enqueue_project_weekly_push",
|
||||
"enqueue_risk_event_generation",
|
||||
]
|
||||
|
||||
@@ -4,3 +4,4 @@ TASK_GENERATE_RISK_EVENTS = "risks.generate_events"
|
||||
TASK_SYNC_LEGACY_PROJECTS = "legacy.sync_projects"
|
||||
TASK_SYNC_LEGACY_TASKS = "legacy.sync_tasks"
|
||||
TASK_DISPATCH_PENDING_EVENTS = "events.dispatch_pending"
|
||||
TASK_RUN_LIFECYCLE = "reports.run_lifecycle"
|
||||
|
||||
50
app/core/background/task_queue/lifecycle.py
Normal file
50
app/core/background/task_queue/lifecycle.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from typing import Any
|
||||
|
||||
from app.core.background.task_queue.constants import TASK_RUN_LIFECYCLE
|
||||
from app.core.config import get_settings
|
||||
from app.core.constants import ActorValue
|
||||
from app.core.database import SessionLocal
|
||||
from app.modules.reports.lifecycle_pipeline import LifecyclePipelineService
|
||||
|
||||
|
||||
def enqueue_lifecycle_report(
|
||||
report_type: str,
|
||||
receive_id: str | None = None,
|
||||
receive_id_type: str = "chat_id",
|
||||
force: bool = False,
|
||||
actor: str = ActorValue.SCHEDULER,
|
||||
) -> dict[str, Any]:
|
||||
db = SessionLocal()
|
||||
try:
|
||||
service = LifecyclePipelineService(db)
|
||||
workflow, period_key, deduplicated = service.prepare(report_type, actor, force)
|
||||
if deduplicated:
|
||||
return {
|
||||
"workflow_code": workflow.code,
|
||||
"period_key": period_key,
|
||||
"deduplicated": True,
|
||||
"status": workflow.status,
|
||||
}
|
||||
if get_settings().task_queue_enabled:
|
||||
from app.tasks import celery_app
|
||||
|
||||
result = celery_app.signature(
|
||||
TASK_RUN_LIFECYCLE,
|
||||
kwargs={
|
||||
"report_type": report_type,
|
||||
"receive_id": receive_id,
|
||||
"receive_id_type": receive_id_type,
|
||||
"force": force,
|
||||
"actor": actor,
|
||||
},
|
||||
).apply_async()
|
||||
return {
|
||||
"workflow_code": workflow.code,
|
||||
"period_key": period_key,
|
||||
"task_id": result.id,
|
||||
"deduplicated": False,
|
||||
"status": "queued",
|
||||
}
|
||||
return service.run(report_type, receive_id, receive_id_type, force, actor)
|
||||
finally:
|
||||
db.close()
|
||||
Reference in New Issue
Block a user