From f391bf0dc71c08177ed763d5d65fe5d20d5a6652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Sun, 24 Feb 2019 11:42:33 -0500 Subject: [PATCH] Added /running_tasks endpoint. --- bazarr/main.py | 6 ++++++ bazarr/scheduler.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/bazarr/main.py b/bazarr/main.py index 633547082..e19fcc7ab 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -1881,6 +1881,12 @@ def notifications(): return None +@route(base_url + 'running_tasks') +@custom_auth_basic(check_credentials) +def running_tasks_list(): + return dict(tasks=running_tasks) + + # Mute 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) diff --git a/bazarr/scheduler.py b/bazarr/scheduler.py index e3843b1a5..bc2cff442 100644 --- a/bazarr/scheduler.py +++ b/bazarr/scheduler.py @@ -15,6 +15,7 @@ from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.triggers.interval import IntervalTrigger from apscheduler.triggers.cron import CronTrigger from apscheduler.triggers.date import DateTrigger +from apscheduler.events import EVENT_JOB_SUBMITTED, EVENT_JOB_EXECUTED from datetime import datetime import pytz from tzlocal import get_localzone @@ -67,6 +68,20 @@ if str(get_localzone()) == "local": else: 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 settings.general.getboolean('auto_update'): scheduler.add_job(check_and_apply_update, IntervalTrigger(hours=6), max_instances=1, coalesce=True,