diff --git a/Dockerfile b/Dockerfile index e677841..bda44a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,6 +21,9 @@ RUN set -ex \ && apt-get autoremove -y \ && apt-get clean -y +# Health check +HEALTHCHECK --interval=1m --timeout=10s --retries=1 \ + CMD python3 healthcheck.py CMD ["python", "main.py"] diff --git a/Scripts/healthcheck.py b/Scripts/healthcheck.py new file mode 100644 index 0000000..bfd9736 --- /dev/null +++ b/Scripts/healthcheck.py @@ -0,0 +1,33 @@ +import asyncio +import sys +import os +import logging + +from bookshelfAPI import bookshelf_user_login +from dotenv import load_dotenv + +# Used only for DOCKER HEALTHCHECK, do not import into MAIN or ANY EXTENSION +load_dotenv() + +logger = logging.getLogger("bot") + + +async def main(): + if __name__ == "__main__": + try: + user_token = os.getenv('bookshelfToken') + result = bookshelf_user_login(token=user_token) + if result: + print('HEALTHCHECK SUCCEEDED!', file=None) + sys.exit(0) + else: + print('HEALTHCHECK FAILED!', file=None) + sys.exit(1) + + except Exception as e: + print('HEALTHCHECK FAILED!', e, file=None) + sys.exit(1) + + +logger.debug('RUNNING HEALTHCHECK') +asyncio.run(main()) diff --git a/Scripts/multi_user.py b/Scripts/multi_user.py index 3fbec20..cba946d 100644 --- a/Scripts/multi_user.py +++ b/Scripts/multi_user.py @@ -23,7 +23,6 @@ def table_create(): user TEXT NOT NULL, token TEXT NOT NULL UNIQUE, discord_id INTEGER NOT NULL, -default_user INTEGER, UNIQUE(user, token) ) ''') @@ -53,7 +52,7 @@ def search_user_db(discord_id=0, user='', token=''): if discord_id != 0 and user == '': logger.info('Searching db using discord ID') cursor.execute(''' - SELECT token, user, default_user FROM users WHERE discord_id = ? + SELECT token, user FROM users WHERE discord_id = ? ''', (discord_id,)) rows = cursor.fetchall() option = 1 @@ -81,7 +80,7 @@ def search_user_db(discord_id=0, user='', token=''): else: logger.info('Searching db for user and token using no arguments') - cursor.execute('''SELECT user, token, default_user FROM users''') + cursor.execute('''SELECT user, token FROM users''') rows = cursor.fetchall() option = 5 diff --git a/Scripts/settings.py b/Scripts/settings.py index 0f2c780..889f746 100644 --- a/Scripts/settings.py +++ b/Scripts/settings.py @@ -6,7 +6,7 @@ load_dotenv(override=True) # Version Info -versionNumber = 'V1.2.8b' +versionNumber = 'V1.2.9' COMMAND_COUNT = 0