zhaohaipeng 17 часов назад
Родитель
Сommit
41bf4d9e10
1 измененных файлов с 26 добавлено и 20 удалено
  1. 26 20
      monitor/supply_workflow_monitor.py

+ 26 - 20
monitor/supply_workflow_monitor.py

@@ -20,7 +20,7 @@ column_width_map = {
     "状态": "80px",
     "任务数": "80px",
     "记录数": "80px",
-
+    "计划数": "80px",
     "待处理": "80px",
     "运行中": "80px",
     "成功": "80px",
@@ -163,28 +163,34 @@ 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]]:
     sql = f"""
-            SELECT sw.name AS '策略名',
+            select sw.name                      AS '策略名',
                    case
                        when sw.status = 1 then '开启中'
                        when sw.status = 0 then '已关闭'
-                       else '未知' end AS 状态,
-                   IFNULL(swt.total_cnt, 0)    AS '任务数',
-                   IFNULL(swt.init_cnt, 0)     AS '待处理',
-                   IFNULL(swt.running_cnt, 0)  AS '运行中',
-                   IFNULL(swt.success_cnt, 0)  AS '成功',
-                   IFNULL(swt.fail_success, 0) AS '失败'
-            FROM supply_workflow sw
-                     LEFT JOIN (
-                                   SELECT workflow_id,
-                                          COUNT(task_id)                                     AS total_cnt,
-                                          COUNT(DISTINCT IF(task_status = 0, task_id, NULL)) AS init_cnt,
-                                          COUNT(DISTINCT IF(task_status = 1, task_id, NULL)) AS running_cnt,
-                                          COUNT(DISTINCT IF(task_status = 2, task_id, NULL)) AS success_cnt,
-                                          COUNT(DISTINCT IF(task_status = 3, task_id, NULL)) AS fail_success
-                                   FROM supply_workflow_task
-                                   WHERE create_timestamp >= {ts}
-                                   GROUP BY workflow_id
-                               ) swt ON sw.id = swt.workflow_id
+                       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,
+                                          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
             ORDER BY sw.status DESC, sw.create_timestamp DESC;
             """
     return mysql_helper.execute_query(sql)