From 349d18b8c3545977220a151759ef019c2bbe6026 Mon Sep 17 00:00:00 2001 From: donkevlar Date: Wed, 2 Oct 2024 23:11:05 -0400 Subject: [PATCH 1/2] Added healthcheck.py and healthcheck to Dockerfile --- Dockerfile | 3 +++ Scripts/healthcheck.py | 33 +++++++++++++++++++++++++++++++++ Scripts/multi_user.py | 5 ++--- 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 Scripts/healthcheck.py 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 From 0a33ecc10d21b965aaa7189af0ee2a4e5cfb0bd8 Mon Sep 17 00:00:00 2001 From: donkevlar Date: Wed, 2 Oct 2024 23:25:58 -0400 Subject: [PATCH 2/2] bumped version to V1.2.9 --- Scripts/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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