diff --git a/app.py b/app.py index 0e1d943..d1cec32 100644 --- a/app.py +++ b/app.py @@ -2,9 +2,8 @@ from flask import Flask, render_template, request, redirect, url_for, flash, ses from flask_sqlalchemy import SQLAlchemy from werkzeug.security import generate_password_hash, check_password_hash import os, paramiko, threading, time, io, tempfile, csv -from datetime import datetime, timedelta, timezone - from apscheduler.schedulers.background import BackgroundScheduler +from datetime import datetime, timezone, timedelta from io import StringIO import socket import ipaddress @@ -1128,13 +1127,12 @@ def scheduled_deployments(): deploy_user(setting.user_id) setting.last_deploy_time = now db.session.commit() + +scheduler = BackgroundScheduler(timezone="UTC") +scheduler.add_job(func=scheduled_deployments, trigger="interval", minutes=5, next_run_time=datetime.now()) +scheduler.add_job(func=automated_backups, trigger="interval", minutes=5, next_run_time=datetime.now()) +scheduler.add_job(func=cleanup_old_backups, trigger="interval", hours=24, next_run_time=datetime.now()) -scheduler = BackgroundScheduler() -scheduler.add_job(func=scheduled_deployments, trigger="interval", minutes=5) -scheduler.add_job(func=automated_backups, trigger="interval", minutes=5) -scheduler.add_job(func=cleanup_old_backups, trigger="interval", hours=24) - -scheduler.start() if __name__ == '__main__': with app.app_context(): diff --git a/run_waitress.py b/run_waitress.py index 9ff0b01..0641b9d 100644 --- a/run_waitress.py +++ b/run_waitress.py @@ -1,7 +1,12 @@ from waitress import serve -from app import app, scheduler +from app import app, scheduler, db +from datetime import datetime if __name__ == "__main__": + with app.app_context(): + db.create_all() + for job in scheduler.get_jobs(): + job.modify(next_run_time=datetime.now()) if not scheduler.running: scheduler.start() - serve(app, listen="*:5580", threads=4, ident="") \ No newline at end of file + serve(app, listen="*:5580", threads=4, ident="")