diff --git a/Dockerfile b/Dockerfile index f0c2398..923d588 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ COPY . . RUN ["chmod", "+x", "./src/main.sh"] -CMD ./src/main.sh +CMD ["./src/main.sh", "--test"] # docker compose build # docker compose up diff --git a/src/finder.py b/src/finder.py index 97901cb..87ffec1 100644 --- a/src/finder.py +++ b/src/finder.py @@ -39,7 +39,6 @@ DRIVER: Optional[webdriver.Chrome] = None WAIT: Optional[WebDriverWait] = None BOT = None -timeout: Optional[pendulum.DateTime] = None def setup_chrome_options(env: Environment) -> webdriver.ChromeOptions: @@ -254,13 +253,6 @@ async def notify_users_and_unsubscribe(course: Course, msg: str, users: list[str DB.unsubscribe(str(course), uid) -async def notify_admin(msg: str): - """Sends a notification to Telegram feedback channel.""" - await BOT.send_message( - FEEDBACK_CHANNEL_ID, msg, write_timeout=TimeConstants.TIMEOUT_SECONDS - ) - - def driver_alive() -> bool: """Check if the WebDriver is still operational.""" if DRIVER is None: @@ -283,26 +275,5 @@ def init(context: ContextTypes.DEFAULT_TYPE): async def run(context: ContextTypes.DEFAULT_TYPE): - """Runs the finder every minute.""" - global timeout - - if (now := pendulum.now()).minute % 30 == 0: - print("Finder started at", now.to_rss_string()) - init(context) - - try: - await search_courses() - except TimeoutException: - if timeout is None: - timeout = pendulum.now() - else: - minutes_since_last_timeout = pendulum.now().diff(timeout).in_minutes() - if minutes_since_last_timeout % 20 == 0: - await notify_admin( - f"Finder timed out for {minutes_since_last_timeout} minutes." - ) - except Exception as exc: - await notify_admin(repr(exc)) - else: - timeout = None + await search_courses() diff --git a/src/main.sh b/src/main.sh index 1f138c2..2ad1da6 100755 --- a/src/main.sh +++ b/src/main.sh @@ -4,7 +4,13 @@ SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) python -m fastapi run $SCRIPT_DIR/server.py & -python $(dirname $SCRIPT_DIR)/test/bot.py & +if [ "$1" == "--test" ]; then + BOT_PROGRAM="$(dirname $SCRIPT_DIR)/test/bot.py" +else + BOT_PROGRAM="$SCRIPT_DIR/bot.py" +fi + +python $BOT_PROGRAM & wait -n diff --git a/test/bot.py b/test/bot.py index 79bcfc4..cfdf4d5 100644 --- a/test/bot.py +++ b/test/bot.py @@ -1,7 +1,6 @@ import os import sys import logging -import asyncio sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from src import bot @@ -14,4 +13,4 @@ if __name__ == "__main__": - asyncio.run(bot.main(Environment.DEV)) + bot.main(Environment.DEV)