feat(crons): changed crons
This commit is contained in:
parent
b18945e59b
commit
9808c4af4f
1 changed files with 13 additions and 24 deletions
|
|
@ -1,30 +1,19 @@
|
|||
print("============= CRONS =============")
|
||||
import sys
|
||||
|
||||
import logging
|
||||
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
from decouple import config
|
||||
from fastapi import FastAPI
|
||||
|
||||
from routers.crons import core_crons, core_dynamic_crons
|
||||
|
||||
app = FastAPI()
|
||||
from routers.crons import core_dynamic_crons
|
||||
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
return {"status": "Running"}
|
||||
def process(action):
|
||||
{
|
||||
"TELEMETRY": core_dynamic_crons.telemetry_cron,
|
||||
"JOB": core_dynamic_crons.run_scheduled_jobs,
|
||||
"REPORT": core_dynamic_crons.weekly_report2
|
||||
}.get(action.upper(), lambda: print(f"{action} not found in crons-definitions"))()
|
||||
|
||||
|
||||
app.schedule = AsyncIOScheduler()
|
||||
app.schedule.start()
|
||||
|
||||
if not config("LOCAL_CRONS", default=False, cast=bool):
|
||||
for job in core_crons.cron_jobs + core_dynamic_crons.cron_jobs + core_dynamic_crons.SINGLE_CRONS:
|
||||
app.schedule.add_job(id=job["func"].__name__, **job)
|
||||
|
||||
logging.basicConfig(level=config("LOGLEVEL", default=logging.INFO))
|
||||
logging.getLogger('apscheduler').setLevel(config("LOGLEVEL", default=logging.INFO))
|
||||
|
||||
else:
|
||||
print("Nothing to do because LOCAL_CRONS mode is enabled.")
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 2 or len(sys.argv[1]) < 1:
|
||||
print("please provide actions as argument")
|
||||
else:
|
||||
process(sys.argv[1])
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue