fix empty base on 1st start
All checks were successful
Test Build / test-build (push) Successful in 1s
All checks were successful
Test Build / test-build (push) Successful in 1s
This commit is contained in:
44
app.py
44
app.py
@@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
from flask import Flask, session, request
|
from flask import Flask, session, request
|
||||||
|
from sqlalchemy import inspect
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
# 1. Загрузка переменных окружения - в самом верху
|
# 1. Загрузка переменных окружения - в самом верху
|
||||||
@@ -62,26 +63,29 @@ def create_app():
|
|||||||
login_manager.login_message_category = "info"
|
login_manager.login_message_category = "info"
|
||||||
|
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
from models import User, UserConfig
|
if inspect(db.engine).has_table('user_config'):
|
||||||
all_configs = UserConfig.query.all()
|
from models import User, UserConfig
|
||||||
for config in all_configs:
|
all_configs = UserConfig.query.all()
|
||||||
user_id = config.user_id
|
for config in all_configs:
|
||||||
mappings = config.mappings
|
user_id = config.user_id
|
||||||
for sheer_title, params in mappings.items():
|
mappings = config.mappings
|
||||||
cron_schedule = params.get('schedule_cron')
|
for sheer_title, params in mappings.items():
|
||||||
if cron_schedule:
|
cron_schedule = params.get('schedule_cron')
|
||||||
job_id = f"user_{user_id}_sheet_{sheer_title}"
|
if cron_schedule:
|
||||||
try:
|
job_id = f"user_{user_id}_sheet_{sheer_title}"
|
||||||
scheduler.add_job(
|
try:
|
||||||
id=job_id,
|
scheduler.add_job(
|
||||||
func=execute_olap_export,
|
id=job_id,
|
||||||
trigger='cron',
|
func=execute_olap_export,
|
||||||
args=[user_id, sheer_title],
|
trigger='cron',
|
||||||
**_parse_cron_string(cron_schedule)
|
args=[user_id, sheer_title],
|
||||||
)
|
**_parse_cron_string(cron_schedule)
|
||||||
app.logger.info(f"Job {job_id} loaded on startup.")
|
)
|
||||||
except Exception as e:
|
app.logger.info(f"Job {job_id} loaded on startup.")
|
||||||
app.logger.error(f"Failed to load job {job_id}: {e}")
|
except Exception as e:
|
||||||
|
app.logger.error(f"Failed to load job {job_id}: {e}")
|
||||||
|
else:
|
||||||
|
app.logger.warning("Database tables not found. Skipping job loading on startup. Run 'flask init-db' to create the tables.")
|
||||||
scheduler.start()
|
scheduler.start()
|
||||||
|
|
||||||
# --- Регистрация команд CLI ---
|
# --- Регистрация команд CLI ---
|
||||||
|
|||||||
Reference in New Issue
Block a user