feat: scheduler 儲存於 SQLAlchemyJobStore, 並在定時輸入時間時加入判斷.

This commit is contained in:
CHunYenc
2022-09-17 14:44:23 +08:00
parent c811b895d7
commit 8e356923c7
2 changed files with 27 additions and 2 deletions
+11 -2
View File
@@ -1,6 +1,6 @@
from flask import Blueprint, request, render_template
from flask_apscheduler.utils import job_to_dict
from datetime import datetime as dt
from applications.common.tasks import tasks
from applications.common.tasks.tasks import task_list
from applications.common.utils.http import table_api, fail_api, success_api
@@ -56,12 +56,22 @@ def save():
run_date=datetime,
replace_existing=True)
elif type == 'interval':
# load time
time = dt.strptime(time, "%H:%M:%S").time()
interval_seconds = 0
if time.hour != 0:
interval_seconds += time.hour * 60 * 60
if time.minute != 0:
interval_seconds += time.minute * 60
if time.second != 0:
interval_seconds += time.second
scheduler.add_job(
func=getattr(tasks, functions),
id=_id,
name=name,
args=(1, 1),
trigger=type,
seconds=interval_seconds,
replace_existing=True)
elif type == 'cron':
scheduler.add_job(
@@ -71,7 +81,6 @@ def save():
args=(1, 1),
trigger=type,
replace_existing=True)
return success_api()