新增 消息定时推送功能
This commit is contained in:
@@ -496,3 +496,55 @@ class TaskDBOperator(BaseDBOperator):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"获取任务日志失败: {e}")
|
logger.error(f"获取任务日志失败: {e}")
|
||||||
return {'logs': [], 'total': 0, 'page': page, 'limit': limit}
|
return {'logs': [], 'total': 0, 'page': page, 'limit': limit}
|
||||||
|
|
||||||
|
def get_tasks_count(self) -> int:
|
||||||
|
"""获取任务总数
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
任务总数
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
sql = "SELECT COUNT(*) as total FROM t_push_tasks"
|
||||||
|
result = self.execute_query(sql, fetch_one=True)
|
||||||
|
return result['total'] if result else 0
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"获取任务总数失败: {e}")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def get_tasks_count_by_status(self, status: str) -> int:
|
||||||
|
"""获取指定状态的任务数量
|
||||||
|
|
||||||
|
Args:
|
||||||
|
status: 任务状态
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
任务数量
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
sql = "SELECT COUNT(*) as total FROM t_push_tasks WHERE status = %s"
|
||||||
|
result = self.execute_query(sql, (status,), fetch_one=True)
|
||||||
|
return result['total'] if result else 0
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"获取{status}状态任务数量失败: {e}")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def get_tasks_count_by_date(self, date: str) -> int:
|
||||||
|
"""获取指定日期的任务数量
|
||||||
|
|
||||||
|
Args:
|
||||||
|
date: 日期,格式:YYYY-MM-DD
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
任务数量
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
sql = """
|
||||||
|
SELECT COUNT(*) as total
|
||||||
|
FROM t_push_tasks
|
||||||
|
WHERE DATE(created_at) = %s
|
||||||
|
"""
|
||||||
|
result = self.execute_query(sql, (date,), fetch_one=True)
|
||||||
|
return result['total'] if result else 0
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"获取{date}任务数量失败: {e}")
|
||||||
|
return 0
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Dict, Any, List, Optional, Tuple
|
from typing import Dict, Any, List, Optional, Tuple
|
||||||
|
|
||||||
@@ -139,6 +140,10 @@ class MessagePushTask(MessagePluginInterface):
|
|||||||
content_link = task.get('content_link')
|
content_link = task.get('content_link')
|
||||||
content_miniprogram = task.get('content_miniprogram')
|
content_miniprogram = task.get('content_miniprogram')
|
||||||
groups = task.get('groups', [])
|
groups = task.get('groups', [])
|
||||||
|
try:
|
||||||
|
groups = json.loads(groups)
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
raise Exception("无发送清单")
|
||||||
|
|
||||||
# 记录任务开始执行
|
# 记录任务开始执行
|
||||||
self.db.log_task_action({
|
self.db.log_task_action({
|
||||||
|
|||||||
Reference in New Issue
Block a user