Added error handling for connection errors to the MySQL server

doc_update
Joey Hines 2018-08-19 09:57:19 -05:00
parent c82178604e
commit f801016a5b
2 changed files with 8 additions and 5 deletions

View File

@ -15,9 +15,9 @@ from BotConfig import bot_config
def setup_logging(): def setup_logging():
discord_logger = logging.getLogger('discord') discord_logger = logging.getLogger('discord')
discord_logger.setLevel(logging.WARNING) discord_logger.setLevel(logging.INFO)
sql_logger = logging.getLogger('sqlalchemy.engine') sql_logger = logging.getLogger('sqlalchemy.engine')
sql_logger.setLevel(logging.WARNING) sql_logger.setLevel(logging.INFO)
bot_info_logger = logging.getLogger('bot') bot_info_logger = logging.getLogger('bot')
bot_info_logger.setLevel(logging.INFO) bot_info_logger.setLevel(logging.INFO)

9
bot.py
View File

@ -11,6 +11,8 @@ from Commands import Commands
from DatabaseModels import Player from DatabaseModels import Player
from MinecraftAccountInfoGrabber import * from MinecraftAccountInfoGrabber import *
from pymysql.err import OperationalError
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
description = ''' description = '''
@ -87,6 +89,8 @@ async def on_command_error(error, ctx):
error_str = 'Use a shorter name or a smaller value, dong ding.' error_str = 'Use a shorter name or a smaller value, dong ding.'
elif isinstance(error.original, NotOnServerError): elif isinstance(error.original, NotOnServerError):
error_str = 'Command needs to be run on 24CC. Run this command there whoever you are.'.format() error_str = 'Command needs to be run on 24CC. Run this command there whoever you are.'.format()
elif isinstance(error.original, OperationalError):
error_str = 'Database connection issue, looks like some admin has to fix something.'.format()
else: else:
logger.error("Geoffrey encountered unhandled exception: %s", error) logger.error("Geoffrey encountered unhandled exception: %s", error)
error_str = bad_error_message.format(ctx.invoked_with, error) error_str = bad_error_message.format(ctx.invoked_with, error)
@ -113,13 +117,12 @@ async def username_update():
except UsernameLookupFailed: except UsernameLookupFailed:
logger.info("Username lookup error.") logger.info("Username lookup error.")
session.rollback() session.rollback()
except OperationalError:
logger.info("MySQL connection error")
finally: finally:
session.close() session.close()
await asyncio.sleep(600) await asyncio.sleep(600)
if session is not None:
session.close()
def start_bot(): def start_bot():
try: try: