Skip to content

Commit

Permalink
Merge pull request #578 from RockChinQ/fix/blocked-audit-upload
Browse files Browse the repository at this point in the history
[Fix] 阻塞地发送审计报告数据
  • Loading branch information
RockChinQ authored Sep 28, 2023
2 parents ac80764 + 3f4ed4d commit a113785
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions pkg/audit/gatherer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import hashlib
import json
import logging
import threading

import requests

Expand Down Expand Up @@ -42,15 +43,20 @@ def report_to_server(self, subservice_name: str, count: int):
只会报告此次请求的使用量,不会报告总量。
不包含除版本号、使用类型、使用量以外的任何信息,仅供开发者分析使用情况。
"""
try:
config = pkg.utils.context.get_config()
if not config.report_usage:

def thread_func():

try:
config = pkg.utils.context.get_config()
if not config.report_usage:
return
res = requests.get("http://reports.rockchin.top:18989/usage?service_name=qchatgpt.{}&version={}&count={}&msg_source={}".format(subservice_name, self.version_str, count, config.msg_source_adapter))
if res.status_code != 200 or res.text != "ok":
logging.warning("report to server failed, status_code: {}, text: {}".format(res.status_code, res.text))
except:
return
res = requests.get("http://reports.rockchin.top:18989/usage?service_name=qchatgpt.{}&version={}&count={}&msg_source={}".format(subservice_name, self.version_str, count, config.msg_source_adapter))
if res.status_code != 200 or res.text != "ok":
logging.warning("report to server failed, status_code: {}, text: {}".format(res.status_code, res.text))
except:
return

threading.Thread(target=thread_func).start()

def get_usage(self, key_md5):
return self.usage[key_md5] if key_md5 in self.usage else {}
Expand Down

0 comments on commit a113785

Please sign in to comment.