mirror of
https://gitlab.com/chicken-riders/RcGcDb.git
synced 2025-02-23 00:54:09 +00:00
Add wiki debug for pg pubsub
This commit is contained in:
parent
b67d1ee834
commit
25bc1948cb
|
@ -47,6 +47,17 @@ class DiscordMessageMetadata:
|
|||
def __str__(self):
|
||||
return f"<DiscordMessageMetadata page_id={self.page_id} log_id={self.log_id} rev_id={self.rev_id}>"
|
||||
|
||||
def json(self) -> dict:
|
||||
dict_obj = {
|
||||
"method": self.method,
|
||||
"page_id": self.page_id,
|
||||
"log_id": self.log_id,
|
||||
"rev_id": self.rev_id,
|
||||
"message_display": self.message_display,
|
||||
"time_of_change": str(self.time_of_change)
|
||||
}
|
||||
return dict_obj
|
||||
|
||||
def matches(self, other: dict):
|
||||
for key, value in other.items():
|
||||
if self.__dict__[key] != value:
|
||||
|
@ -95,6 +106,13 @@ class DiscordMessage:
|
|||
def __len__(self):
|
||||
return self.length
|
||||
|
||||
def json(self):
|
||||
dict_obj = {
|
||||
"length": self.length,
|
||||
"metadata": self.metadata.json()
|
||||
}
|
||||
return dict_obj
|
||||
|
||||
def matches(self, other: dict):
|
||||
return self.metadata.matches(other)
|
||||
|
||||
|
@ -195,6 +213,16 @@ class StackedDiscordMessage():
|
|||
message_structure["components"] = self.message_list[0].webhook_object["components"]
|
||||
return json.dumps(message_structure)
|
||||
|
||||
def json(self) -> dict:
|
||||
dict_obj = {
|
||||
"length": self.length,
|
||||
"message_type": self.message_type,
|
||||
"discord_callback_message_id": self.discord_callback_message_id,
|
||||
"webhook": self.webhook[-3:] if self.webhook else None,
|
||||
"messages": [message.json() for message in self.message_list]
|
||||
}
|
||||
return dict_obj
|
||||
|
||||
def check_for_length(self, message_length: int):
|
||||
if self.message_type:
|
||||
return len(self) + message_length > 6000 or len(self.message_list) > 9
|
||||
|
|
|
@ -97,9 +97,13 @@ class DomainManager:
|
|||
json_object["domains"][name] = domain.json()
|
||||
for message in messagequeue._queue:
|
||||
json_object["queued_messages"].append({"metadata": str(message.discord_message.metadata), "url": message.wiki.script_url})
|
||||
await connection.execute("select pg_notify('debugresponse', $1);", json.dumps(json_object))
|
||||
elif split_payload[1] == "RESPONSE":
|
||||
return
|
||||
await connection.execute("select pg_notify('debugresponse', 'DUMP ' || $1);", json.dumps(json_object))
|
||||
elif split_payload[1] == "SITE":
|
||||
domain = self.return_domain(self.get_domain(split_payload[2]))
|
||||
wiki = domain.get_wiki(split_payload[2])
|
||||
if wiki is not None:
|
||||
await connection.execute("select pg_notify('debugresponse', 'SITE ' || $1 || ' ' || $2);",
|
||||
wiki.script_url, json.dumps(wiki.json()))
|
||||
else:
|
||||
raise ValueError("Unknown pub/sub command! Payload: {}".format(payload))
|
||||
|
||||
|
|
16
src/wiki.py
16
src/wiki.py
|
@ -65,6 +65,22 @@ class Wiki:
|
|||
f"<statistics={self.statistics} tags={self.tags} first_fetch_done={self.first_fetch_done}, rc_targets={self.rc_targets}, discussion_targets={self.discussion_targets},"
|
||||
f"recache_requested={self.recache_requested}>")
|
||||
|
||||
def json(self) -> dict:
|
||||
dict_obj = {
|
||||
"wiki_url": self.script_url,
|
||||
"tags": self.tags,
|
||||
"first_fetch_done": self.first_fetch_done,
|
||||
"rc_targets": {str(x): [webhook_url[-3:] 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[-3:] 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,
|
||||
"last_checked_rc": self.statistics.last_checked_rc,
|
||||
"last_action": self.statistics.last_action
|
||||
}
|
||||
if self.domain.name == "fandom.com":
|
||||
dict_obj.update(last_checked_discussion=self.statistics.last_checked_discussion, last_post=self.statistics.last_post)
|
||||
return dict_obj
|
||||
|
||||
@property
|
||||
def rc_id(self):
|
||||
return self.statistics.last_action
|
||||
|
|
Loading…
Reference in a new issue