Skip to content

Commit

Permalink
remove _success_callback
Browse files Browse the repository at this point in the history
  • Loading branch information
JS00000 committed Apr 9, 2023
1 parent 8ee7a48 commit f687b2b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 9 deletions.
5 changes: 0 additions & 5 deletions channel/chat_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,6 @@ def _send(self, reply: Reply, context: Context, retry_cnt = 0):
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))

Expand All @@ -245,8 +242,6 @@ def func(worker:Future):
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:
Expand Down
1 change: 0 additions & 1 deletion channel/wechatmp/ServiceAccount.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def POST(self):
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"

Expand Down
5 changes: 2 additions & 3 deletions channel/wechatmp/wechatmp_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def send(self, reply: Reply, context: Context):
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"]
Expand All @@ -114,12 +115,10 @@ def send(self, reply: Reply, context: Context):
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)

0 comments on commit f687b2b

Please sign in to comment.