visuddhinanda 8 месяцев назад
Родитель
Сommit
a900bacf4c
2 измененных файлов с 5 добавлено и 4 удалено
  1. 3 2
      ai-translate/ai_translate/service.py
  2. 2 2
      ai-translate/ai_translate/worker.py

+ 3 - 2
ai-translate/ai_translate/service.py

@@ -106,7 +106,7 @@ class Message:
 class AiTranslateService:
     """AI翻译服务"""
 
-    def __init__(self, redis, ch, method, api_url, openai_proxy, customer_timeout):
+    def __init__(self, redis, ch, method, api_url, openai_proxy, customer_timeout, worker_name: str):
         self.queue = 'ai_translate'
         self.model_token = None
         self.task = None
@@ -120,6 +120,7 @@ class AiTranslateService:
         self.channel = ch
         self.maxProcessTime = 15 * 60  # 一个句子的最大处理时间
         self.openai_proxy = openai_proxy
+        self.worker_name = worker_name
 
     def process_translate(self, message_id: str, body: Message) -> bool:
         """处理翻译任务"""
@@ -156,7 +157,7 @@ class AiTranslateService:
                 self.task.id,
                 'task',
                 self.task.title,
-                f'id:{message_id}',
+                f'id:{message_id} worker:{self.worker_name}',
                 None
             )
         times = [self.maxProcessTime]

+ 2 - 2
ai-translate/ai_translate/worker.py

@@ -7,12 +7,12 @@ from .utils import is_stopped
 logger = logging.getLogger(__name__)
 
 
-def handle_message(redis, ch, method, id, content_type, body, api_url: str, openai_proxy: str, customer_timeout: int):
+def handle_message(redis, ch, method, id, content_type, body, api_url: str, openai_proxy: str, customer_timeout: int, worker_name: str):
     MaxRetry: int = 3
     try:
         logger.info("process message start (%s) messages", len(body.payload))
         consumer = AiTranslateService(
-            redis, ch, method, api_url, openai_proxy, customer_timeout)
+            redis, ch, method, api_url, openai_proxy, customer_timeout, worker_name)
         messages = ns_to_dataclass([body], Message)
         consumer.process_translate(id, messages[0])
         logger.info(f'message {id} ack')