mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-07-21 06:07:13 +08:00
fix: add debug log
This commit is contained in:
@@ -199,34 +199,38 @@ class MJBot:
|
|||||||
return reply
|
return reply
|
||||||
|
|
||||||
async def check_task(self, task: MJTask, e_context: EventContext):
|
async def check_task(self, task: MJTask, e_context: EventContext):
|
||||||
max_retry_times = 90
|
try:
|
||||||
while max_retry_times > 0:
|
logger.debug(f"[MJ] start check task status, {task}")
|
||||||
await asyncio.sleep(10)
|
max_retry_times = 90
|
||||||
async with aiohttp.ClientSession() as session:
|
while max_retry_times > 0:
|
||||||
url = f"{self.base_url}/tasks/{task.id}"
|
await asyncio.sleep(10)
|
||||||
try:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.get(url, headers=self.headers) as res:
|
url = f"{self.base_url}/tasks/{task.id}"
|
||||||
if res.status == 200:
|
try:
|
||||||
res_json = await res.json()
|
async with session.get(url, headers=self.headers) as res:
|
||||||
logger.debug(f"[MJ] task check res, task_id={task.id}, status={res.status}, "
|
if res.status == 200:
|
||||||
f"data={res_json.get('data')}, thread={threading.current_thread().name}")
|
res_json = await res.json()
|
||||||
if res_json.get("data") and res_json.get("data").get("status") == Status.FINISHED.name:
|
logger.debug(f"[MJ] task check res, task_id={task.id}, status={res.status}, "
|
||||||
# process success res
|
f"data={res_json.get('data')}, thread={threading.current_thread().name}")
|
||||||
if self.tasks.get(task.id):
|
if res_json.get("data") and res_json.get("data").get("status") == Status.FINISHED.name:
|
||||||
self.tasks[task.id].status = Status.FINISHED
|
# process success res
|
||||||
self._process_success_task(task, res_json.get("data"), e_context)
|
if self.tasks.get(task.id):
|
||||||
return
|
self.tasks[task.id].status = Status.FINISHED
|
||||||
else:
|
self._process_success_task(task, res_json.get("data"), e_context)
|
||||||
res_json = await res.json()
|
return
|
||||||
logger.warn(f"[MJ] image check error, status_code={res.status}, res={res_json}")
|
else:
|
||||||
max_retry_times -= 20
|
res_json = await res.json()
|
||||||
except Exception as e:
|
logger.warn(f"[MJ] image check error, status_code={res.status}, res={res_json}")
|
||||||
max_retry_times -= 20
|
max_retry_times -= 20
|
||||||
logger.warn(e)
|
except Exception as e:
|
||||||
max_retry_times -= 1
|
max_retry_times -= 20
|
||||||
logger.warn("[MJ] end from poll")
|
logger.warn(e)
|
||||||
if self.tasks.get(task.id):
|
max_retry_times -= 1
|
||||||
self.tasks[task.id].status = Status.EXPIRED
|
logger.warn("[MJ] end from poll")
|
||||||
|
if self.tasks.get(task.id):
|
||||||
|
self.tasks[task.id].status = Status.EXPIRED
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(e)
|
||||||
|
|
||||||
def _process_success_task(self, task: MJTask, res: dict, e_context: EventContext):
|
def _process_success_task(self, task: MJTask, res: dict, e_context: EventContext):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user