diff --git a/app.py b/app.py index 0da79fd..e642de7 100644 --- a/app.py +++ b/app.py @@ -1390,14 +1390,41 @@ def delete_old_logs(): flash(f"Usunięto {deleted_count} logów starszych niż {delete_days} dni.") return redirect(url_for('logs_page')) +#if __name__ == '__main__': +# with app.app_context(): +# #scheduler = BackgroundScheduler() +# schedule_retention_job() +# schedule_auto_export_job() +# schedule_auto_binary_backup_job() +# scheduler.add_job(func=cleanup_old_logs, trigger='interval', days=1, id="cleanup_logs_job") +# +# scheduler.start() +# atexit.register(lambda: scheduler.shutdown()) +# app.run(host='0.0.0.0', port=5581, use_reloader=False, debug=True) + if __name__ == '__main__': with app.app_context(): - #scheduler = BackgroundScheduler() - schedule_retention_job() - schedule_auto_export_job() - schedule_auto_binary_backup_job() - scheduler.add_job(func=cleanup_old_logs, trigger='interval', days=1, id="cleanup_logs_job") + # Usunięcie istniejących zadań, jeśli istnieją + try: + scheduler.remove_job("cleanup_job") + except Exception: + pass + try: + scheduler.remove_job("auto_backup_job") + except Exception: + pass + try: + scheduler.remove_job("cleanup_logs_job") + except Exception: + pass + # Dodanie zadań z wrapperem kontekstu + scheduler.add_job(func=run_task_with_context(cleanup_old_backups), trigger='interval', days=1, id="cleanup_job") + scheduler.add_job(func=run_task_with_context(scheduled_auto_backup), trigger='interval', days=1, id="auto_backup_job") + scheduler.add_job(func=run_task_with_context(cleanup_old_logs), trigger='interval', days=1, id="cleanup_logs_job") + + # Uruchomienie harmonogramu scheduler.start() atexit.register(lambda: scheduler.shutdown()) + app.run(host='0.0.0.0', port=5581, use_reloader=False, debug=True)