diff --git a/main.py b/main.py index 9e516d0..7070459 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,7 @@ import os import dotenv import sys import json +from apscheduler.schedulers.background import BackgroundScheduler class GunicornApp(BaseApplication): @@ -24,6 +25,10 @@ class GunicornApp(BaseApplication): return self.application if __name__ == '__main__': + scheduler = BackgroundScheduler() + scheduler.add_job(func=server.check_payments, trigger="interval", seconds=10) + scheduler.start() + workers = os.getenv('WORKERS') threads = os.getenv('THREADS') if workers is None: diff --git a/server.py b/server.py index 6a0ab67..fc0d017 100644 --- a/server.py +++ b/server.py @@ -293,13 +293,16 @@ def not_found(e): return render_template('404.html'), 404 -def repeat_check_payments(): +def repeat_check_payments(auto=False): # Run check_payments function payments.check_payments() # Schedule the function to run again after 10 seconds - threading.Timer(10, repeat_check_payments).start() - + if not auto: + threading.Timer(10, repeat_check_payments).start() +def check_payments(): + print('Checking payments', flush=True) + payments.check_payments() if __name__ == '__main__': # Set timer for payments