From 3c43db829e028faabe9e1f404ab05f43cbafb377 Mon Sep 17 00:00:00 2001 From: Jake <j.vondoemming@stud.uni-goettingen.de> Date: Mon, 27 Nov 2023 13:51:51 +0100 Subject: [PATCH 1/2] started scheduler --- aocp/__init__.py | 15 +++++++++++++++ aocp/verifier.py | 5 ++++- requirements.txt | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/aocp/__init__.py b/aocp/__init__.py index bc803f3..339f2af 100644 --- a/aocp/__init__.py +++ b/aocp/__init__.py @@ -8,8 +8,10 @@ from . import score import os import json import pprint +import time from flask import Flask, abort, redirect, render_template, request, session +from flask_apscheduler import APScheduler def create_app(test_config=None): @@ -105,4 +107,17 @@ def create_app(test_config=None): # Initialize score score.init_app(app) + # initialize scheduler + scheduler = APScheduler() + scheduler.init_app(app) + @scheduler.task('interval', id='do_verifier', seconds=10, misfire_grace_time=900) + def verifier_job(): + with app.app_context(): + app.logger.info("Running verifier job") + verifier.verify() + app.logger.info("Finished running verifier job") + + scheduler.start() + + return app diff --git a/aocp/verifier.py b/aocp/verifier.py index ba4fcf3..dc70395 100644 --- a/aocp/verifier.py +++ b/aocp/verifier.py @@ -35,15 +35,18 @@ def verify(): if status == aoc.Status.PASS: db.update_submission_status(userid=uid,day=day,value=val,status="CORRECT") db.set_day_solution(day,val) + current_app.logger.info("Found solution for day %d.", day) elif status == aoc.Status.FAIL: db.update_submission_status(userid=uid,day=day,value=val,status="INCORRECT") + current_app.logger.info("Tried a solution for day %d, but AOC says its wrong.", day) elif status == aoc.Status.RATE_LIMIT: + current_app.logger.info("AOC has rate limited us for further %d seconds.", timeout) if timeout: time.sleep(timeout) elif status == aoc.Status.NOT_LOGGED_IN: current_app.logger.error("no/invalid aoc session cookie.") elif status == aoc.Status.COMPLETED: - current_app.logger.warning("request made although puzzle already solved. not good.") + current_app.logger.error("AOC says this was already completed.") elif status == aoc.Status.UNKNOWN: current_app.logger.warning("unknown status returned.") diff --git a/requirements.txt b/requirements.txt index 74149a9..99f8f75 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,3 +11,4 @@ dateparser>=1.1.8 requests>=2.31.0 authlib>=1.2.1 pandas>=2.1.2 +Flask-APScheduler>=1.13.1 -- GitLab From 44713481b8b9b0fcee4169643a8e0fae566a910b Mon Sep 17 00:00:00 2001 From: Jake <j.vondoemming@stud.uni-goettingen.de> Date: Mon, 27 Nov 2023 16:22:39 +0100 Subject: [PATCH 2/2] increased timeout to get less rate limited --- aocp/verifier.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aocp/verifier.py b/aocp/verifier.py index dc70395..911da06 100644 --- a/aocp/verifier.py +++ b/aocp/verifier.py @@ -42,7 +42,7 @@ def verify(): elif status == aoc.Status.RATE_LIMIT: current_app.logger.info("AOC has rate limited us for further %d seconds.", timeout) if timeout: - time.sleep(timeout) + time.sleep(timeout + 2) elif status == aoc.Status.NOT_LOGGED_IN: current_app.logger.error("no/invalid aoc session cookie.") elif status == aoc.Status.COMPLETED: -- GitLab