diff --git a/web/app/app.py b/web/app/app.py index 2859655..0bbeb0a 100644 --- a/web/app/app.py +++ b/web/app/app.py @@ -66,12 +66,14 @@ def register_extensions(app): migrate.init_app(app, db) bootstrap.init_app(app) + ''' if scheduler.state == 0: print("Scheduler init app") scheduler.init_app(app) logging.getLogger("apscheduler").setLevel(logging.INFO) print("Scheduler start") scheduler.start() + ''' return app diff --git a/web/config.py b/web/config.py index 910b99a..0ddc3a4 100644 --- a/web/config.py +++ b/web/config.py @@ -114,6 +114,15 @@ class PostgresConfig(Config): user=POSTGRES_USER, pw=POSTGRES_PW, url=POSTGRES_URL, db=POSTGRES_DB ) + JOBS = [ + { + "id": "update_server", + "func": 'app.services.cron_service:check_db_sessions', + "trigger": "interval", + "seconds": int(os.environ.get("INTERVAL_DB_CHECK")) or 3, + } + ] + class TestConfig(Config): TESTING = True diff --git a/web/gunicorn.conf.py b/web/gunicorn.conf.py new file mode 100644 index 0000000..7fe1ac4 --- /dev/null +++ b/web/gunicorn.conf.py @@ -0,0 +1,14 @@ + + +def on_starting(server): + print("Gunicorn master process is starting...") + +def when_ready(server): + from app.app import create_app, scheduler + app = create_app() # Create an instance of the app + with app.app_context(): + print("Initializing and starting scheduler inside Gunicorn master process") + scheduler.init_app(app) # Initialize the scheduler + scheduler.start() # Start the scheduler + + print("Scheduler started in Gunicorn master process")