mirror of
https://gitlab.com/chicken-riders/RcGcDb.git
synced 2025-02-23 00:54:09 +00:00
Fixed possible unhandled exception, added debug messages, attempted to fix global exception handler
This commit is contained in:
parent
eb222bf8b4
commit
8e85588ebd
|
@ -14,10 +14,12 @@ from src.misc import get_paths
|
||||||
from src.msgqueue import messagequeue
|
from src.msgqueue import messagequeue
|
||||||
from src.queue_handler import DBHandler
|
from src.queue_handler import DBHandler
|
||||||
from src.wiki import Wiki, process_cats, process_mwmsgs, essential_info
|
from src.wiki import Wiki, process_cats, process_mwmsgs, essential_info
|
||||||
|
from src.discord import DiscordMessage
|
||||||
|
|
||||||
logging.config.dictConfig(settings["logging"])
|
logging.config.dictConfig(settings["logging"])
|
||||||
logger = logging.getLogger("rcgcdb.bot")
|
logger = logging.getLogger("rcgcdb.bot")
|
||||||
logger.debug("Current settings: {settings}".format(settings=settings))
|
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
|
# Log Fail states with structure wiki_url: number of fail states
|
||||||
all_wikis: dict = {}
|
all_wikis: dict = {}
|
||||||
|
@ -65,7 +67,7 @@ async def wiki_scanner():
|
||||||
logger.debug("Wiki {}".format(db_wiki["wiki"]))
|
logger.debug("Wiki {}".format(db_wiki["wiki"]))
|
||||||
extended = False
|
extended = False
|
||||||
if db_wiki["wiki"] not in all_wikis:
|
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()
|
all_wikis[db_wiki["wiki"]] = Wiki()
|
||||||
local_wiki = all_wikis[db_wiki["wiki"]] # set a reference to a wiki object from memory
|
local_wiki = all_wikis[db_wiki["wiki"]] # set a reference to a wiki object from memory
|
||||||
if local_wiki.mw_messages is None:
|
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"""
|
"""Global exception handler for asyncio, lets us know when something crashes"""
|
||||||
msg = context.get("exception", context["message"])
|
msg = context.get("exception", context["message"])
|
||||||
logger.error("Global exception handler: {}".format(msg))
|
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():
|
async def main_loop():
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
@ -152,7 +153,7 @@ async def main_loop():
|
||||||
loop.add_signal_handler(
|
loop.add_signal_handler(
|
||||||
s, lambda s=s: shutdown(loop, signal=s))
|
s, lambda s=s: shutdown(loop, signal=s))
|
||||||
except AttributeError:
|
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)
|
signals = (signal.SIGBREAK, signal.SIGTERM, signal.SIGINT)
|
||||||
loop.set_exception_handler(global_exception_handler)
|
loop.set_exception_handler(global_exception_handler)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -149,4 +149,6 @@ async def handle_discord_http(code, formatted_embed, result, dmsg):
|
||||||
logger.error(
|
logger.error(
|
||||||
"Discord have trouble processing the event, and because the HTTP code returned is {} it means we blame them.".format(
|
"Discord have trouble processing the event, and because the HTTP code returned is {} it means we blame them.".format(
|
||||||
code))
|
code))
|
||||||
return 3
|
return 3
|
||||||
|
else:
|
||||||
|
return 4
|
||||||
|
|
|
@ -14,6 +14,10 @@ from bs4 import BeautifulSoup
|
||||||
|
|
||||||
logger = logging.getLogger("rcgcdw.rc_formatters")
|
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,
|
async def compact_formatter(action, change, parsed_comment, categories, recent_changes, target, _, ngettext, paths,
|
||||||
additional_data=None):
|
additional_data=None):
|
||||||
"""Recent Changes compact formatter, part of RcGcDw"""
|
"""Recent Changes compact formatter, part of RcGcDw"""
|
||||||
|
|
|
@ -88,6 +88,7 @@ class Wiki:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def remove(wiki_url, reason):
|
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(wiki_url, reason)
|
||||||
await src.discord.wiki_removal_monitor(wiki_url, reason)
|
await src.discord.wiki_removal_monitor(wiki_url, reason)
|
||||||
db_cursor.execute('DELETE FROM rcgcdw WHERE wiki = ?', (wiki_url,))
|
db_cursor.execute('DELETE FROM rcgcdw WHERE wiki = ?', (wiki_url,))
|
||||||
|
|
Loading…
Reference in a new issue