Fixes to serialization of JSON and added more debug statements

This commit is contained in:
Frisk 2024-07-22 16:25:25 +02:00
parent a92ea598e1
commit efbe074044
3 changed files with 14 additions and 2 deletions

View file

@ -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):

View file

@ -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"<Log {self.type.name} at {datetime.fromtimestamp(float(self.time)).isoformat()} on {self.title} with details: {self.details}>"

View file

@ -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
}