Fixed possible unhandled exception, added debug messages, attempted to fix global exception handler

This commit is contained in:
Frisk 2020-07-29 18:33:40 +02:00
parent eb222bf8b4
commit 8e85588ebd
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
4 changed files with 13 additions and 5 deletions

View file

@ -14,10 +14,12 @@ from src.misc import get_paths
from src.msgqueue import messagequeue
from src.queue_handler import DBHandler
from src.wiki import Wiki, process_cats, process_mwmsgs, essential_info
from src.discord import DiscordMessage
logging.config.dictConfig(settings["logging"])
logger = logging.getLogger("rcgcdb.bot")
logger.debug("Current settings: {settings}".format(settings=settings))
logger.info("RcGcDb v.{} is starting up.".format("1.0"))
# Log Fail states with structure wiki_url: number of fail states
all_wikis: dict = {}
@ -65,7 +67,7 @@ async def wiki_scanner():
logger.debug("Wiki {}".format(db_wiki["wiki"]))
extended = False
if db_wiki["wiki"] not in all_wikis:
logger.debug("New wiki: {}".format(db_wiki["wiki"]))
logger.info("Registering new wiki locally: {}".format(db_wiki["wiki"]))
all_wikis[db_wiki["wiki"]] = Wiki()
local_wiki = all_wikis[db_wiki["wiki"]] # set a reference to a wiki object from memory
if local_wiki.mw_messages is None:
@ -141,8 +143,7 @@ def global_exception_handler(loop, context):
"""Global exception handler for asyncio, lets us know when something crashes"""
msg = context.get("exception", context["message"])
logger.error("Global exception handler: {}".format(msg))
requests.post("https://discord.com/api/webhooks/" + settings["monitoring_webhook"], data={"content": "test"})
requests.post("https://discord.com/api/webhooks/"+settings["monitoring_webhook"], data=repr(DiscordMessage("compact", "monitoring", [settings["monitoring_webhook"]], wiki=None, content="[RcGcDb] Global exception handler: {}".format(msg))))
async def main_loop():
loop = asyncio.get_event_loop()
@ -152,7 +153,7 @@ async def main_loop():
loop.add_signal_handler(
s, lambda s=s: shutdown(loop, signal=s))
except AttributeError:
logger.info("Running on Windows huh? This complicates things")
logger.info("Running on Windows, some things may not work as they should.")
signals = (signal.SIGBREAK, signal.SIGTERM, signal.SIGINT)
loop.set_exception_handler(global_exception_handler)
try:

View file

@ -149,4 +149,6 @@ async def handle_discord_http(code, formatted_embed, result, dmsg):
logger.error(
"Discord have trouble processing the event, and because the HTTP code returned is {} it means we blame them.".format(
code))
return 3
return 3
else:
return 4

View file

@ -14,6 +14,10 @@ from bs4 import BeautifulSoup
logger = logging.getLogger("rcgcdw.rc_formatters")
if 1 == 2: # additional translation strings in unreachable code
print(_("director"), _("bot"), _("editor"), _("directors"), _("sysop"), _("bureaucrat"), _("reviewer"),
_("autoreview"), _("autopatrol"), _("wiki_guardian"), ngettext("second", "seconds", 1), ngettext("minute", "minutes", 1), ngettext("hour", "hours", 1), ngettext("day", "days", 1), ngettext("week", "weeks", 1), ngettext("month", "months",1), ngettext("year", "years", 1), ngettext("millennium", "millennia", 1), ngettext("decade", "decades", 1), ngettext("century", "centuries", 1))
async def compact_formatter(action, change, parsed_comment, categories, recent_changes, target, _, ngettext, paths,
additional_data=None):
"""Recent Changes compact formatter, part of RcGcDw"""

View file

@ -88,6 +88,7 @@ class Wiki:
@staticmethod
async def remove(wiki_url, reason):
logger.info("Removing a wiki {}".format(wiki_url))
await src.discord.wiki_removal(wiki_url, reason)
await src.discord.wiki_removal_monitor(wiki_url, reason)
db_cursor.execute('DELETE FROM rcgcdw WHERE wiki = ?', (wiki_url,))