Skip to content

Commit

Permalink
Merge pull request #47
Browse files Browse the repository at this point in the history
Healthcheck
  • Loading branch information
donkevlar authored Oct 3, 2024
2 parents a02fb14 + 0a33ecc commit 7a04218
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
33 changes: 33 additions & 0 deletions Scripts/healthcheck.py
Original file line number Diff line number Diff line change
@@ -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())
5 changes: 2 additions & 3 deletions Scripts/multi_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
''')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Scripts/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
load_dotenv(override=True)

# Version Info
versionNumber = 'V1.2.8b'
versionNumber = 'V1.2.9'

COMMAND_COUNT = 0

Expand Down

0 comments on commit 7a04218

Please sign in to comment.