From efbe074044810b406d1b33ec3c05d36d124bcc51 Mon Sep 17 00:00:00 2001 From: Frisk Date: Mon, 22 Jul 2024 16:25:25 +0200 Subject: [PATCH] Fixes to serialization of JSON and added more debug statements --- src/domain_manager.py | 5 ++++- src/statistics.py | 9 +++++++++ src/wiki.py | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/domain_manager.py b/src/domain_manager.py index 215e630..a0b061f 100644 --- a/src/domain_manager.py +++ b/src/domain_manager.py @@ -84,6 +84,7 @@ class DomainManager: logger.info("RCGCDBDEBUG Wiki information for {}: {}".format(split_payload[2], domain.get_wiki(split_payload[2]))) elif split_payload[1] == "DUMP": # Dump debug info JSON object into postgres pubsub channel + logger.info(f"Received {' '.join(split_payload)} on pub/sub. Preparing JSON with data...") json_object = {"uptime": time.time() - self.start_time, "domain_count": len(self.domains), "wiki_count": sum([len(x.wikis) for x in self.domains.values()]), "tasks": {}, @@ -99,14 +100,16 @@ class DomainManager: json_object["queued_messages"].append({"metadata": str(message.discord_message.metadata), "url": message.wiki.script_url}) await connection.execute("select pg_notify('debugresponse', 'DUMP ' || $1);", json.dumps(json_object)) elif split_payload[1] == "SITE": + logger.info(f"Received {' '.join(split_payload)} on pub/sub. Preparing JSON with data...") req_id = split_payload[2] domain = self.return_domain(self.get_domain(split_payload[3])) wiki = domain.get_wiki(split_payload[3]) if wiki is not None: + logger.debug("Wiki specified in pub/sub message has been found. Preparing and sending dump.") await connection.execute("select pg_notify('debugresponse', 'SITE ' || $1 || ' ' || $2);", req_id, json.dumps(wiki.json())) else: - raise ValueError("Unknown pub/sub command! Payload: {}".format(payload)) + logger.error("Unknown pub/sub command! Payload: {}".format(payload)) async def new_wiki(self, wiki: Wiki): diff --git a/src/statistics.py b/src/statistics.py index 3818aaf..b6de2bd 100644 --- a/src/statistics.py +++ b/src/statistics.py @@ -27,6 +27,15 @@ class Log: def __str__(self): return self.__repr__() + def json(self): + dict_obj = { + "type": self.type.name, + "time": self.time, + "title": self.title, + "details": self.details + } + return dict_obj + def __repr__(self): return f"" diff --git a/src/wiki.py b/src/wiki.py index bf00f37..4473962 100644 --- a/src/wiki.py +++ b/src/wiki.py @@ -73,7 +73,7 @@ class Wiki: "rc_targets": {str(x): [webhook_url.split("/")[0] for webhook_url in y] for x, y in self.rc_targets.items()} if self.rc_targets else None, "discussion_targets": {str(x): [webhook_url.split("/")[0] for webhook_url in y] for x, y in self.discussion_targets.items()} if self.discussion_targets else None, "namespaces": self.namespaces, - "logs": self.statistics.logs, + "logs": [x.json() for x in self.statistics.logs], "last_checked_rc": self.statistics.last_checked_rc, "last_action": self.statistics.last_action }