41 lines
829 B
Python
41 lines
829 B
Python
from apscheduler.schedulers.background import BackgroundScheduler
|
|
|
|
from app.config import settings
|
|
from app.database import SessionLocal
|
|
from app.services import run_sync, send_reminders
|
|
|
|
|
|
scheduler = BackgroundScheduler(timezone="Europe/Berlin")
|
|
|
|
|
|
def sync_job():
|
|
with SessionLocal() as db:
|
|
run_sync(db)
|
|
|
|
|
|
def reminder_job():
|
|
with SessionLocal() as db:
|
|
send_reminders(db)
|
|
|
|
|
|
def start_scheduler():
|
|
if scheduler.running:
|
|
return
|
|
|
|
scheduler.add_job(
|
|
sync_job,
|
|
"interval",
|
|
hours=settings.poll_interval_hours,
|
|
id="sync_job",
|
|
replace_existing=True,
|
|
)
|
|
scheduler.add_job(
|
|
reminder_job,
|
|
"interval",
|
|
hours=settings.reminder_interval_hours,
|
|
id="reminder_job",
|
|
replace_existing=True,
|
|
)
|
|
scheduler.start()
|
|
|