openreplay/api/app_alerts.py
Taha Yassine Kraiem 03ea03aba2 feat(alerts): refactored alerts
feat(alerts): fixed decimal precision
feat(alerts): configurable cron-interval
2022-01-11 11:05:50 +01:00

28 lines
867 B
Python

import logging
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from decouple import config
from fastapi import FastAPI
from chalicelib.core import alerts_processor
app = FastAPI()
print("============= ALERTS =============")
@app.get("/")
async def root():
return {"status": "Running"}
app.schedule = AsyncIOScheduler()
app.schedule.start()
app.schedule.add_job(id="alerts_processor", **{"func": alerts_processor.process, "trigger": "interval",
"minutes": config("ALERTS_INTERVAL", cast=int, default=5),
"misfire_grace_time": 20})
for job in app.schedule.get_jobs():
print({"Name": str(job.id), "Run Frequency": str(job.trigger), "Next Run": str(job.next_run_time)})
logging.basicConfig()
logging.getLogger('apscheduler').setLevel(logging.INFO)