Fixed some improper debug responses

This commit is contained in:
Frisk 2024-09-09 22:38:21 +02:00
parent 9fd1cc9904
commit 409678b2cb
2 changed files with 17 additions and 4 deletions

View file

@ -105,7 +105,7 @@ class MessageQueue:
logger.error("MessageQueue.suspension_check failed due to lack of messages belonging to a webhook ID {} in message queue".format(webhook_url.split("/")[0])) logger.error("MessageQueue.suspension_check failed due to lack of messages belonging to a webhook ID {} in message queue".format(webhook_url.split("/")[0]))
return return
logger.debug("Attempting to send messages for the suspended webhook.") logger.debug("Attempting to send messages for the suspended webhook.")
await self.send_msg_set(webhook_messages) await self.send_msg_set((webhook_url, webhook_messages,))
@staticmethod @staticmethod
def compare_message_to_dict(metadata: DiscordMessageMetadata, to_match: dict): def compare_message_to_dict(metadata: DiscordMessageMetadata, to_match: dict):

View file

@ -36,6 +36,18 @@ class DomainManager:
def __init__(self): def __init__(self):
self.domains: dict[str, Domain] = {} self.domains: dict[str, Domain] = {}
self.start_time: float = time.time() self.start_time: float = time.time()
self.task_store: dict[str, asyncio.Task] = {}
asyncio.create_task(self.task_tracker(), name="TaskTracer")
async def task_tracker(self, one_update=False):
"""Task tracer is supposed to keep track of all tasks spawned for /debug endpoint to show them.
It replaces asyncio.all_tasks() in order to show even tasks that have finished running."""
while 1:
for task in asyncio.all_tasks():
self.task_store[task.get_name()] = task
if one_update:
return
await asyncio.sleep(3600.0)
@staticmethod @staticmethod
def chunkstring(payload, length): def chunkstring(payload, length):
@ -102,8 +114,9 @@ class DomainManager:
"awaiting_DB_queries": dbmanager.json(), "awaiting_DB_queries": dbmanager.json(),
"total_discord_messages_sent": sum([x.total_discord_messages_sent for x in self.domains.values()]) "total_discord_messages_sent": sum([x.total_discord_messages_sent for x in self.domains.values()])
} }
for task in asyncio.all_tasks(): await self.task_tracker(one_update=True)
json_object["tasks"][task.get_name()] = {"done": task.done(), "result": result_handler(task.result()) if task.done() else None} for task_name, task in self.task_store.items():
json_object["tasks"][task_name] = {"done": task.done(), "result": result_handler(task.result()) if task.done() else None}
for name, domain in self.domains.items(): for name, domain in self.domains.items():
json_object["domains"][name] = domain.json() json_object["domains"][name] = domain.json()
for message in messagequeue._queue: for message in messagequeue._queue:
@ -130,7 +143,7 @@ class DomainManager:
wiki_json["wiki_rc"] = await wiki.api_request(params=params, timeout=5) wiki_json["wiki_rc"] = await wiki.api_request(params=params, timeout=5)
except: except:
wiki_json["wiki_rc"] = None wiki_json["wiki_rc"] = None
json_string: str = json.dumps(wiki.json()) json_string: str = json.dumps(wiki_json)
for json_part in self.chunkstring(json_string, 7950): for json_part in self.chunkstring(json_string, 7950):
await connection.execute("select pg_notify('debugresponse', 'SITE CHUNK ' || $1 || ' ' || $2);", await connection.execute("select pg_notify('debugresponse', 'SITE CHUNK ' || $1 || ' ' || $2);",
req_id, json_part) req_id, json_part)