From f687b2b6f4580b00c9d58e2cf48ff43e59811cd8 Mon Sep 17 00:00:00 2001
From: JS00000 <js00000000000000000@gmail.com>
Date: Sun, 9 Apr 2023 18:32:09 +0800
Subject: [PATCH] remove _success_callback

---
 channel/chat_channel.py              | 5 -----
 channel/wechatmp/ServiceAccount.py   | 1 -
 channel/wechatmp/wechatmp_channel.py | 5 ++---
 3 files changed, 2 insertions(+), 9 deletions(-)

diff --git a/channel/chat_channel.py b/channel/chat_channel.py
index 9ef3d41..5000ae3 100644
--- a/channel/chat_channel.py
+++ b/channel/chat_channel.py
@@ -233,9 +233,6 @@ class ChatChannel(Channel):
                 time.sleep(3+3*retry_cnt)
                 self._send(reply, context, retry_cnt+1)
 
-    def _success_callback(self, session_id, **kwargs): # 线程正常结束时的回调函数
-        pass
-
     def _fail_callback(self, session_id, exception, **kwargs): # 线程异常结束时的回调函数
         logger.exception("Worker return exception: {}".format(exception))
 
@@ -245,8 +242,6 @@ class ChatChannel(Channel):
                 worker_exception = worker.exception()
                 if worker_exception:
                     self._fail_callback(session_id, exception = worker_exception, **kwargs)
-                else:
-                    self._success_callback(session_id, **kwargs)
             except CancelledError as e:
                 logger.info("Worker cancelled, session_id = {}".format(session_id))
             except Exception as e:
diff --git a/channel/wechatmp/ServiceAccount.py b/channel/wechatmp/ServiceAccount.py
index 60d40db..ae535ea 100644
--- a/channel/wechatmp/ServiceAccount.py
+++ b/channel/wechatmp/ServiceAccount.py
@@ -34,7 +34,6 @@ class Query():
                     user_data = conf().get_user_data(from_user)
                     context['openai_api_key'] = user_data.get('openai_api_key') # None or user openai_api_key
                     channel.produce(context)
-                    channel.running.add(from_user)
                 # The reply will be sent by channel.send() in another thread
                 return "success"
 
diff --git a/channel/wechatmp/wechatmp_channel.py b/channel/wechatmp/wechatmp_channel.py
index 940f9e3..0457606 100644
--- a/channel/wechatmp/wechatmp_channel.py
+++ b/channel/wechatmp/wechatmp_channel.py
@@ -97,6 +97,7 @@ class WechatMPChannel(ChatChannel):
         if self.passive_reply:
             receiver = context["receiver"]
             self.cache_dict[receiver] = reply.content
+            self.running.remove(receiver)
             logger.info("[send] reply to {} saved to cache: {}".format(receiver, reply))
         else:
             receiver = context["receiver"]
@@ -114,12 +115,10 @@ class WechatMPChannel(ChatChannel):
             logger.info("[send] Do send to {}: {}".format(receiver, reply_text))
         return
 
-    def _success_callback(self, session_id, **kwargs): # 线程正常结束时的回调函数
-        self.running.remove(session_id)
 
     def _fail_callback(self, session_id, exception, context, **kwargs): # 线程异常结束时的回调函数
         logger.exception("[wechatmp] Fail to generation message to user, msgId={}, exception={}".format(context['msg'].msg_id, exception))
         if self.passive_reply:
             assert session_id not in self.cache_dict
-        self.running.remove(session_id)
+            self.running.remove(session_id)