From 1292adc7aafa34a7c93c80390826bdc5b6d05cbf Mon Sep 17 00:00:00 2001
From: wu_xinjun <bent20140204@outlook.com>
Date: 星期一, 27 六月 2022 17:14:06 +0800
Subject: [PATCH] add replay_to func for task

---
 src/engine/MessageThreads.py |   49 +++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/src/engine/MessageThreads.py b/src/engine/MessageThreads.py
index 8cc2344..d8cf0c2 100644
--- a/src/engine/MessageThreads.py
+++ b/src/engine/MessageThreads.py
@@ -7,6 +7,7 @@
 from typing import List
 import numpy as np
 import cv2
+import requests
 
 # # add python path of src to sys.path
 # src_path = os.path.join(__file__, *(['..'] * 2))
@@ -151,13 +152,15 @@
     def __init__(self,
         queue_list:List[queue.Queue],
         queue_tags:List[str],
-        task_folder:dict[str,str]):
+        task_folder:dict[str,str],
+        replay_host:str):
         super().__init__()
 
         self.queue_list = queue_list
         self.queue_tags = queue_tags
         self.queue_num = 0
         self.task_folder = task_folder
+        self.replay_host = replay_host
         self.is_stop = False
 
         assert len(self.queue_list) == len(self.queue_tags)
@@ -238,7 +241,12 @@
 
             # display the info to the console
             curr_time = datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
-            print(f"[x] {curr_time}|(From {msg_source}): {msg_context}" )
+            notice_str = f"[x] {curr_time}|(From {msg_source}): {msg_context}"
+            print(notice_str)
+            replay_to_(host = self.replay_host,
+                        message=notice_str,
+                        message_type="logs",
+                        taskuuid=taskuuid)
 
             # next msg
             count += 1
@@ -282,7 +290,12 @@
 
                     # display the info to the console
                     curr_time = datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
-                    print(f"[x] {curr_time}|(From {msg_source}): image{id} saved!" )
+                    notice_str = f"[x] {curr_time}|(From {msg_source}): image{id} saved!"
+                    print(notice_str)
+                    replay_to_(host = self.replay_host,
+                                message=notice_str,
+                                message_type="images",
+                                taskuuid=taskuuid)
 
                 # next image item
                 id += 1
@@ -330,6 +343,15 @@
                     filename = f"{msg_timestamp}-{msg_source}-pointcloud{id}"
                     write_ply(data_array,save_folder,filename)
 
+                    # display the info to the console
+                    curr_time = datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
+                    notice_str = f"[x] {curr_time}|(From {msg_source}): ply{id} saved!"
+                    print(notice_str)
+                    replay_to_(host = self.replay_host,
+                                message=notice_str,
+                                message_type="plys",
+                                taskuuid=taskuuid)
+
                 # next ply item
                 id += 1
 
@@ -338,6 +360,25 @@
 
         raise NotImplementedError("NOT IMPLEMENT!")
 
+
+def replay_to_(host:str,
+            message:str,
+            message_type:str,
+            taskuuid:str, 
+            ):
+
+    if taskuuid != "init":
+        try:
+            # target = host+taskuuid
+            target = host
+            print(f"Send message to [{target}]")
+            payload = {"taskid":taskuuid, "messagetype":message_type, "message": message}
+            r = requests.post(target,params = payload,timeout=3)
+            print("send success!")
+        except Exception as e:
+            print(e)
+            print("send error!")
+            pass
 
 
 def send_logs_tool(logs:List[str],
@@ -442,7 +483,7 @@
                     # end the outer while loop and triminate this function
 
                 else:
-                    print("[x] NO poindcloud has been captured!")
+                    print("[x] NO pointcloud has been captured!")
                 run = False
         else:
             time.sleep(3)

--
Gitblit v1.9.1