From c146375a219621e13c187df66c45971a4f50aa6c Mon Sep 17 00:00:00 2001 From: lixin Date: Thu, 9 Nov 2023 15:51:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0agent=5Ftask=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uos-sysmig.sql | 33 +++++++++++++++++++++++++++++++++ views/server.py | 17 ++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/uos-sysmig.sql b/uos-sysmig.sql index 4a33bb0..9f31049 100644 --- a/uos-sysmig.sql +++ b/uos-sysmig.sql @@ -80,6 +80,39 @@ LOCK TABLES `task_stream` WRITE; /*!40000 ALTER TABLE `task_stream` ENABLE KEYS */; UNLOCK TABLES; +-- +-- Table structure for table `agent_task` +-- + +DROP TABLE IF EXISTS `agent_task`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `agent_task` ( + `agent_id` int NOT NULL, + `agent_ip` varchar(256) DEFAULT NULL, + `task_id` int DEFAULT NULL, + `task_stream_id` int DEFAULT NULL, + `task_code` varchar(256) DEFAULT NULL, + `task_type` int DEFAULT NULL, + `task_status` int DEFAULT NULL, + `task_progress` int DEFAULT NULL, + `task_CreateTime` timestamp NULL DEFAULT NULL, + `task_Updatetime` timestamp NULL DEFAULT NULL, + `task_data` varchar(256) DEFAULT NULL, + PRIMARY KEY (`agent_id`), + KEY `task_id` (`task_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `agent_task` +-- + +LOCK TABLES `agent_task` WRITE; +/*!40000 ALTER TABLE `agent_task` DISABLE KEYS */; +/*!40000 ALTER TABLE `agent_task` ENABLE KEYS */; +UNLOCK TABLES; + -- -- Table structure for table `cur_task` -- diff --git a/views/server.py b/views/server.py index 49353b4..cf07d2f 100644 --- a/views/server.py +++ b/views/server.py @@ -62,4 +62,19 @@ def create_task_stream(agent_ip): agent_id = get_agent_id(agent_ip) time = datetime.now().strftime('%Y-%-m-%d %H:%M:%S') values = ((agent_ip, agent_id, stream_status, time, time),) - DBHelper().insert(create_task_stream_sql, values) \ No newline at end of file + DBHelper().insert(create_task_stream_sql, values) + + create_cur_task_sql = "insert into cur_task(task_status,stream_CreateTime,stream_Updatetime," \ + "agent_ip) values (%s, %s, %s, %s);" + values = (('None', time, time, agent_ip),) + DBHelper().insert(create_cur_task_sql, values) + + get_task_id = "select max(task_id) task_id from cur_task" + task_id = DBHelper().execute(get_task_id).fetchone() + task_stream_id_sql = "select task_stream_id from task_stream where agent_ip='%s'" % agent_ip + task_stream_id = DBHelper().execute(task_stream_id_sql).fetchone() + values = ((agent_id, agent_ip, task_id[0], 0, 0, time, time, task_stream_id[0], "00"),) + create_agent_task_sql = "insert into agent_task(agent_id,agent_ip,task_id,task_status,task_progress," \ + "task_CreateTime,task_Updatetime,task_stream_id,task_data) values " \ + "(%s, %s, %s, %s, %s, %s, %s, %s, %s);" + DBHelper().insert(create_agent_task_sql, values) \ No newline at end of file -- 2.20.1