Added /running_tasks endpoint.

This commit is contained in:
Louis Vézina 2019-02-24 11:42:33 -05:00
parent 7d823a2930
commit f391bf0dc7
2 changed files with 21 additions and 0 deletions

View File

@ -1881,6 +1881,12 @@ def notifications():
return None return None
@route(base_url + 'running_tasks')
@custom_auth_basic(check_credentials)
def running_tasks_list():
return dict(tasks=running_tasks)
# Mute DeprecationWarning # Mute DeprecationWarning
warnings.simplefilter("ignore", DeprecationWarning) warnings.simplefilter("ignore", DeprecationWarning)
server = WSGIServer((str(settings.general.ip), (int(args.port) if args.port else int(settings.general.port))), app, handler_class=WebSocketHandler) server = WSGIServer((str(settings.general.ip), (int(args.port) if args.port else int(settings.general.port))), app, handler_class=WebSocketHandler)

View File

@ -15,6 +15,7 @@ from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.interval import IntervalTrigger from apscheduler.triggers.interval import IntervalTrigger
from apscheduler.triggers.cron import CronTrigger from apscheduler.triggers.cron import CronTrigger
from apscheduler.triggers.date import DateTrigger from apscheduler.triggers.date import DateTrigger
from apscheduler.events import EVENT_JOB_SUBMITTED, EVENT_JOB_EXECUTED
from datetime import datetime from datetime import datetime
import pytz import pytz
from tzlocal import get_localzone from tzlocal import get_localzone
@ -67,6 +68,20 @@ if str(get_localzone()) == "local":
else: else:
scheduler = BackgroundScheduler() scheduler = BackgroundScheduler()
global running_tasks
running_tasks = []
def task_listener(event):
if event.job_id in running_tasks:
running_tasks.remove(event.job_id)
else:
running_tasks.append(event.job_id)
scheduler.add_listener(task_listener, EVENT_JOB_SUBMITTED | EVENT_JOB_EXECUTED)
if not args.no_update: if not args.no_update:
if settings.general.getboolean('auto_update'): if settings.general.getboolean('auto_update'):
scheduler.add_job(check_and_apply_update, IntervalTrigger(hours=6), max_instances=1, coalesce=True, scheduler.add_job(check_and_apply_update, IntervalTrigger(hours=6), max_instances=1, coalesce=True,