diff --git a/src/discord/queue.py b/src/discord/queue.py index 9848085..2c205fa 100644 --- a/src/discord/queue.py +++ b/src/discord/queue.py @@ -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])) return 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 def compare_message_to_dict(metadata: DiscordMessageMetadata, to_match: dict): diff --git a/src/domain_manager.py b/src/domain_manager.py index 5555e74..1cfe7cd 100644 --- a/src/domain_manager.py +++ b/src/domain_manager.py @@ -36,6 +36,18 @@ class DomainManager: def __init__(self): self.domains: dict[str, Domain] = {} 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 def chunkstring(payload, length): @@ -102,8 +114,9 @@ class DomainManager: "awaiting_DB_queries": dbmanager.json(), "total_discord_messages_sent": sum([x.total_discord_messages_sent for x in self.domains.values()]) } - for task in asyncio.all_tasks(): - json_object["tasks"][task.get_name()] = {"done": task.done(), "result": result_handler(task.result()) if task.done() else None} + await self.task_tracker(one_update=True) + 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(): json_object["domains"][name] = domain.json() for message in messagequeue._queue: @@ -130,7 +143,7 @@ class DomainManager: wiki_json["wiki_rc"] = await wiki.api_request(params=params, timeout=5) except: 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): await connection.execute("select pg_notify('debugresponse', 'SITE CHUNK ' || $1 || ' ' || $2);", req_id, json_part)