Added failed tasks status management.

This commit is contained in:
Louis Vézina 2019-10-31 13:46:05 -04:00
parent 7977deb142
commit f825917c9d
1 changed files with 10 additions and 6 deletions

View File

@ -15,7 +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 apscheduler.events import EVENT_JOB_SUBMITTED, EVENT_JOB_EXECUTED, EVENT_JOB_ERROR
from datetime import datetime
import pytz
from tzlocal import get_localzone
@ -72,14 +72,18 @@ global running_tasks
running_tasks = []
def task_listener(event):
if event.job_id in running_tasks:
running_tasks.remove(event.job_id)
else:
def task_listener_add(event):
if event.job_id not in running_tasks:
running_tasks.append(event.job_id)
scheduler.add_listener(task_listener, EVENT_JOB_SUBMITTED | EVENT_JOB_EXECUTED)
def task_listener_remove(event):
if event.job_id in running_tasks:
running_tasks.remove(event.job_id)
scheduler.add_listener(task_listener_add, EVENT_JOB_SUBMITTED)
scheduler.add_listener(task_listener_remove, EVENT_JOB_EXECUTED | EVENT_JOB_ERROR)
def schedule_update_job():