mirror of
https://gitlab.com/chicken-riders/RcGcDb.git
synced 2025-02-23 00:54:09 +00:00
Fixes to serialization of JSON and added more debug statements
This commit is contained in:
parent
a92ea598e1
commit
efbe074044
|
@ -84,6 +84,7 @@ class DomainManager:
|
||||||
logger.info("RCGCDBDEBUG Wiki information for {}: {}".format(split_payload[2], domain.get_wiki(split_payload[2])))
|
logger.info("RCGCDBDEBUG Wiki information for {}: {}".format(split_payload[2], domain.get_wiki(split_payload[2])))
|
||||||
elif split_payload[1] == "DUMP":
|
elif split_payload[1] == "DUMP":
|
||||||
# Dump debug info JSON object into postgres pubsub channel
|
# 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),
|
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()]),
|
"wiki_count": sum([len(x.wikis) for x in self.domains.values()]),
|
||||||
"tasks": {},
|
"tasks": {},
|
||||||
|
@ -99,14 +100,16 @@ class DomainManager:
|
||||||
json_object["queued_messages"].append({"metadata": str(message.discord_message.metadata), "url": message.wiki.script_url})
|
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))
|
await connection.execute("select pg_notify('debugresponse', 'DUMP ' || $1);", json.dumps(json_object))
|
||||||
elif split_payload[1] == "SITE":
|
elif split_payload[1] == "SITE":
|
||||||
|
logger.info(f"Received {' '.join(split_payload)} on pub/sub. Preparing JSON with data...")
|
||||||
req_id = split_payload[2]
|
req_id = split_payload[2]
|
||||||
domain = self.return_domain(self.get_domain(split_payload[3]))
|
domain = self.return_domain(self.get_domain(split_payload[3]))
|
||||||
wiki = domain.get_wiki(split_payload[3])
|
wiki = domain.get_wiki(split_payload[3])
|
||||||
if wiki is not None:
|
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);",
|
await connection.execute("select pg_notify('debugresponse', 'SITE ' || $1 || ' ' || $2);",
|
||||||
req_id, json.dumps(wiki.json()))
|
req_id, json.dumps(wiki.json()))
|
||||||
else:
|
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):
|
async def new_wiki(self, wiki: Wiki):
|
||||||
|
|
|
@ -27,6 +27,15 @@ class Log:
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.__repr__()
|
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):
|
def __repr__(self):
|
||||||
return f"<Log {self.type.name} at {datetime.fromtimestamp(float(self.time)).isoformat()} on {self.title} with details: {self.details}>"
|
return f"<Log {self.type.name} at {datetime.fromtimestamp(float(self.time)).isoformat()} on {self.title} with details: {self.details}>"
|
||||||
|
|
||||||
|
|
|
@ -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,
|
"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,
|
"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,
|
"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_checked_rc": self.statistics.last_checked_rc,
|
||||||
"last_action": self.statistics.last_action
|
"last_action": self.statistics.last_action
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue