|
|
@@ -20,11 +20,14 @@ column_width_map = {
|
|
|
"状态": "80px",
|
|
|
"任务数": "80px",
|
|
|
"记录数": "80px",
|
|
|
- "计划数": "80px",
|
|
|
- "待处理": "80px",
|
|
|
- "运行中": "80px",
|
|
|
- "成功": "80px",
|
|
|
- "失败": "80px",
|
|
|
+ "当日计划数": "90px",
|
|
|
+ "昨日计划数": "90px",
|
|
|
+ "当日任务数": "90px",
|
|
|
+ "昨日任务数": "90px",
|
|
|
+ "当日待处理": "90px",
|
|
|
+ "当日运行中": "90px",
|
|
|
+ "当日成功": "80px",
|
|
|
+ "当日失败": "80px",
|
|
|
}
|
|
|
|
|
|
header_template = ["wathet", "turquoise", "purple", "indigo", "green", "grey"]
|
|
|
@@ -162,35 +165,53 @@ def build_card_json(body_elements: List[Dict[str, Any]], header: Dict[str, Any],
|
|
|
|
|
|
|
|
|
def supply_workflow_dashboard_stat(ts: int) -> List[Dict[str, Any]]:
|
|
|
+ yesterday = ts - 86400000
|
|
|
+
|
|
|
sql = f"""
|
|
|
- select sw.name AS '策略名',
|
|
|
- case
|
|
|
- when sw.status = 1 then '开启中'
|
|
|
- when sw.status = 0 then '已关闭'
|
|
|
- else '未知' end AS 状态,
|
|
|
- IFNULL(crawler_plan_cnt, 0) as '计划数',
|
|
|
- IFNULL(stat.total_cnt, 0) AS '任务数',
|
|
|
- IFNULL(stat.init_cnt, 0) AS '待处理',
|
|
|
- IFNULL(stat.running_cnt, 0) AS '运行中',
|
|
|
- IFNULL(stat.success_cnt, 0) AS '成功',
|
|
|
- IFNULL(stat.fail_success, 0) AS '失败'
|
|
|
- from supply_workflow sw
|
|
|
- left join (
|
|
|
-
|
|
|
- select swt.workflow_id,
|
|
|
-
|
|
|
- COUNT(distinct swt.task_id) AS total_cnt,
|
|
|
+ SELECT sw.name AS '策略名',
|
|
|
+ CASE
|
|
|
+ WHEN sw.status = 1 THEN '开启中'
|
|
|
+ WHEN sw.status = 0 THEN '已关闭'
|
|
|
+ ELSE '未知'
|
|
|
+ END AS 状态,
|
|
|
+ IFNULL(stat.crawler_plan_cnt, 0) AS '当日计划数',
|
|
|
+ IFNULL(stat_yest.crawler_plan_cnt, 0) AS '昨日计划数',
|
|
|
+ IFNULL(stat.total_cnt, 0) AS '当日任务数',
|
|
|
+ IFNULL(stat_yest.total_cnt, 0) AS '昨日任务数',
|
|
|
+ IFNULL(stat.init_cnt, 0) AS '当日待处理',
|
|
|
+ IFNULL(stat.running_cnt, 0) AS '当日运行中',
|
|
|
+ IFNULL(stat.success_cnt, 0) AS '当日成功',
|
|
|
+ IFNULL(stat.fail_success, 0) AS '当日失败'
|
|
|
+ FROM supply_workflow sw
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT swt.workflow_id,
|
|
|
+ COUNT(DISTINCT swt.task_id) AS total_cnt,
|
|
|
COUNT(DISTINCT IF(task_status = 0, swt.task_id, NULL)) AS init_cnt,
|
|
|
COUNT(DISTINCT IF(task_status = 1, swt.task_id, NULL)) AS running_cnt,
|
|
|
COUNT(DISTINCT IF(task_status = 2, swt.task_id, NULL)) AS success_cnt,
|
|
|
COUNT(DISTINCT IF(task_status = 3, swt.task_id, NULL)) AS fail_success,
|
|
|
- count(distinct swcpr.crawler_plan_id) AS crawler_plan_cnt
|
|
|
- from supply_workflow_task swt
|
|
|
- left join supply_workflow_crawler_plan_record swcpr
|
|
|
- on swt.task_id = swcpr.task_id
|
|
|
- where swt.create_timestamp >= {ts}
|
|
|
- group by swt.workflow_id
|
|
|
- ) stat on sw.id = stat.workflow_id
|
|
|
+ COUNT(DISTINCT swcpr.crawler_plan_id) AS crawler_plan_cnt
|
|
|
+ FROM supply_workflow_task swt
|
|
|
+ LEFT JOIN supply_workflow_crawler_plan_record swcpr
|
|
|
+ ON swt.task_id = swcpr.task_id
|
|
|
+ WHERE swt.create_timestamp >= {ts}
|
|
|
+ GROUP BY swt.workflow_id
|
|
|
+ ) stat ON sw.id = stat.workflow_id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT swt.workflow_id,
|
|
|
+ COUNT(DISTINCT swt.task_id) AS total_cnt,
|
|
|
+ COUNT(DISTINCT IF(task_status = 0, swt.task_id, NULL)) AS init_cnt,
|
|
|
+ COUNT(DISTINCT IF(task_status = 1, swt.task_id, NULL)) AS running_cnt,
|
|
|
+ COUNT(DISTINCT IF(task_status = 2, swt.task_id, NULL)) AS success_cnt,
|
|
|
+ COUNT(DISTINCT IF(task_status = 3, swt.task_id, NULL)) AS fail_success,
|
|
|
+ COUNT(DISTINCT swcpr.crawler_plan_id) AS crawler_plan_cnt
|
|
|
+ FROM supply_workflow_task swt
|
|
|
+ LEFT JOIN supply_workflow_crawler_plan_record swcpr
|
|
|
+ ON swt.task_id = swcpr.task_id
|
|
|
+ WHERE swt.create_timestamp >= {yesterday}
|
|
|
+ AND swt.create_timestamp < {ts}
|
|
|
+ GROUP BY swt.workflow_id
|
|
|
+ ) stat_yest ON sw.id = stat_yest.workflow_id
|
|
|
ORDER BY sw.status DESC, sw.create_timestamp DESC;
|
|
|
"""
|
|
|
return mysql_helper.execute_query(sql)
|
|
|
@@ -395,6 +416,10 @@ def workflow_dashboard_monitor():
|
|
|
dashboard_stat = build_table_element_json(pd.DataFrame(result))
|
|
|
elements = []
|
|
|
if dashboard_stat is not None:
|
|
|
+ dashboard_stat['header_style'] = {
|
|
|
+ "text_size": "normal",
|
|
|
+ "text_align":"center",
|
|
|
+ }
|
|
|
elements.append(dashboard_stat)
|
|
|
else:
|
|
|
elements.append(build_markdown_element_json("**今日workflow还未创建新的任务,请关注**"))
|