| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- from dataclasses import dataclass
- @dataclass
- class TaskConfig:
- """任务配置"""
- timeout: int # 超时时间(秒)
- max_concurrent: int = 5 # 最大并发数
- retry_times: int = 0 # 重试次数
- retryable: bool = True # 是否可重试
- alert_on_failure: bool = True # 失败时是否告警
- class TaskStatus:
- """任务状态常量"""
- INIT = 0
- PROCESSING = 1
- SUCCESS = 2
- FAILED = 99
- class TaskConstants:
- """任务系统常量"""
- # 默认配置
- DEFAULT_TIMEOUT = 1800
- DEFAULT_MAX_CONCURRENT = 5
- DEFAULT_RETRY_TIMES = 0
- # 数据库表名
- TASK_TABLE = "long_articles_task_manager"
- # 所有任务的配置映射
- TASK_CONFIGS = {
- # 监控类任务
- "check_kimi_balance": TaskConfig(
- timeout=20,
- max_concurrent=1,
- retry_times=3,
- ),
- "get_off_videos": TaskConfig(
- timeout=1800,
- max_concurrent=3,
- ),
- "check_publish_video_audit_status": TaskConfig(
- timeout=1800,
- max_concurrent=3,
- ),
- "outside_article_monitor": TaskConfig(
- timeout=3 * 3600,
- max_concurrent=2,
- ),
- "inner_article_monitor": TaskConfig(
- timeout=3600,
- max_concurrent=3,
- ),
- "task_processing_monitor": TaskConfig(
- timeout=300,
- max_concurrent=1,
- ),
- # 爬虫类任务
- "crawler_toutiao": TaskConfig(
- timeout=5 * 3600,
- max_concurrent=3,
- retry_times=2,
- ),
- "crawler_gzh_articles": TaskConfig(
- timeout=4 * 3600,
- max_concurrent=3,
- retry_times=2,
- ),
- "crawler_account_manager": TaskConfig(
- timeout=1800,
- max_concurrent=5,
- ),
- "crawler_detail_analysis": TaskConfig(
- timeout=3600,
- max_concurrent=3,
- ),
- # 数据处理类任务
- "daily_publish_articles_recycle": TaskConfig(
- timeout=3600,
- max_concurrent=2,
- ),
- "update_root_source_id": TaskConfig(
- timeout=3600,
- max_concurrent=2,
- ),
- "recycle_outside_account_articles": TaskConfig(
- timeout=3600,
- max_concurrent=2,
- ),
- "update_outside_account_article_root_source_id": TaskConfig(
- timeout=3600,
- max_concurrent=2,
- ),
- "fwh_daily_recycle": TaskConfig(
- timeout=3600,
- max_concurrent=2,
- ),
- # 算法类任务
- "article_pool_cold_start": TaskConfig(
- timeout=4 * 3600,
- max_concurrent=2,
- retry_times=1,
- ),
- "candidate_account_quality_analysis": TaskConfig(
- timeout=3600,
- max_concurrent=3,
- ),
- "article_pool_category_generation": TaskConfig(
- timeout=3600,
- max_concurrent=3,
- ),
- "account_category_analysis": TaskConfig(
- timeout=3600,
- max_concurrent=3,
- ),
- "update_limited_account_info": TaskConfig(
- timeout=3600,
- max_concurrent=2,
- ),
- # LLM 类任务
- "title_rewrite": TaskConfig(
- timeout=1800,
- max_concurrent=3,
- retry_times=2,
- ),
- "extract_title_features": TaskConfig(
- timeout=1800,
- max_concurrent=3,
- retry_times=2,
- ),
- # 统计分析类任务
- "update_account_read_rate_avg": TaskConfig(
- timeout=1800,
- max_concurrent=3,
- ),
- "update_account_read_avg": TaskConfig(
- timeout=1800,
- max_concurrent=3,
- ),
- "update_account_open_rate_avg": TaskConfig(
- timeout=1800,
- max_concurrent=3,
- ),
- # 自动化任务
- "auto_follow_account": TaskConfig(
- timeout=1800,
- max_concurrent=2,
- ),
- "get_follow_result": TaskConfig(
- timeout=1800,
- max_concurrent=2,
- ),
- "extract_reply_result": TaskConfig(
- timeout=1800,
- max_concurrent=2,
- ),
- # 合作账号任务
- "cooperate_accounts_monitor": TaskConfig(
- timeout=7200,
- max_concurrent=2,
- ),
- "cooperate_accounts_detail": TaskConfig(
- timeout=3600,
- max_concurrent=2,
- ),
- # 其他任务
- "mini_program_detail_process": TaskConfig(
- timeout=1800,
- max_concurrent=3,
- ),
- }
- def get_task_config(task_name: str) -> TaskConfig:
- """获取任务配置,如果不存在则返回默认配置"""
- return TASK_CONFIGS.get(
- task_name,
- TaskConfig(
- timeout=TaskConstants.DEFAULT_TIMEOUT,
- max_concurrent=TaskConstants.DEFAULT_MAX_CONCURRENT,
- retry_times=TaskConstants.DEFAULT_RETRY_TIMES,
- ),
- )
- __all__ = [
- "TaskConfig",
- "TaskStatus",
- "TaskConstants",
- "TASK_CONFIGS",
- "get_task_config",
- ]
|