From e178efb58cadc53d30836ed92d5e6b869bc222c0 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 15 Jan 2023 13:49:16 +0100 Subject: [PATCH] Update for #2653 (AP Scheduler triggers are function calls and not strings anymore) --- cps/schedule.py | 8 ++++---- cps/services/background_scheduler.py | 16 +++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cps/schedule.py b/cps/schedule.py index 5f3326ef..707e9bb3 100644 --- a/cps/schedule.py +++ b/cps/schedule.py @@ -19,7 +19,7 @@ import datetime from . import config, constants -from .services.background_scheduler import BackgroundScheduler, use_APScheduler +from .services.background_scheduler import BackgroundScheduler, CronTrigger, use_APScheduler from .tasks.database import TaskReconnectDatabase from .tasks.thumbnail import TaskGenerateCoverThumbnails, TaskGenerateSeriesThumbnails, TaskClearCoverThumbnailCache from .services.worker import WorkerThread @@ -66,10 +66,10 @@ def register_scheduled_tasks(reconnect=True): duration = config.schedule_duration # Register scheduled tasks - scheduler.schedule_tasks(tasks=get_scheduled_tasks(reconnect), trigger='cron', hour=start) + scheduler.schedule_tasks(tasks=get_scheduled_tasks(reconnect), trigger=CronTrigger(hour=start)) end_time = calclulate_end_time(start, duration) - scheduler.schedule(func=end_scheduled_tasks, trigger='cron', name="end scheduled task", hour=end_time.hour, - minute=end_time.minute) + scheduler.schedule(func=end_scheduled_tasks, trigger=CronTrigger(hour=end_time.hour, minute=end_time.minute), + name="end scheduled task") # Kick-off tasks, if they should currently be running if should_task_be_running(start, duration): diff --git a/cps/services/background_scheduler.py b/cps/services/background_scheduler.py index 27285fd9..ec3555f0 100644 --- a/cps/services/background_scheduler.py +++ b/cps/services/background_scheduler.py @@ -23,6 +23,8 @@ from .worker import WorkerThread try: from apscheduler.schedulers.background import BackgroundScheduler as BScheduler + from apscheduler.triggers.cron import CronTrigger + from apscheduler.triggers.date import DateTrigger use_APScheduler = True except (ImportError, RuntimeError) as e: use_APScheduler = False @@ -47,31 +49,31 @@ class BackgroundScheduler: return cls._instance - def schedule(self, func, trigger, name=None, **trigger_args): + def schedule(self, func, trigger, name=None): if use_APScheduler: - return self.scheduler.add_job(func=func, trigger=trigger, name=name, **trigger_args) + return self.scheduler.add_job(func=func, trigger=trigger, name=name) # Expects a lambda expression for the task - def schedule_task(self, task, user=None, name=None, hidden=False, trigger='cron', **trigger_args): + def schedule_task(self, task, user=None, name=None, hidden=False, trigger=None): if use_APScheduler: def scheduled_task(): worker_task = task() worker_task.scheduled = True WorkerThread.add(user, worker_task, hidden=hidden) - return self.schedule(func=scheduled_task, trigger=trigger, name=name, **trigger_args) + return self.schedule(func=scheduled_task, trigger=trigger, name=name) # Expects a list of lambda expressions for the tasks - def schedule_tasks(self, tasks, user=None, trigger='cron', **trigger_args): + def schedule_tasks(self, tasks, user=None, trigger=None): if use_APScheduler: for task in tasks: - self.schedule_task(task[0], user=user, trigger=trigger, name=task[1], hidden=task[2], **trigger_args) + self.schedule_task(task[0], user=user, trigger=trigger, name=task[1], hidden=task[2]) # Expects a lambda expression for the task def schedule_task_immediately(self, task, user=None, name=None, hidden=False): if use_APScheduler: def immediate_task(): WorkerThread.add(user, task(), hidden) - return self.schedule(func=immediate_task, trigger='date', name=name) + return self.schedule(func=immediate_task, trigger=DateTrigger(), name=name) # Expects a list of lambda expressions for the tasks def schedule_tasks_immediately(self, tasks, user=None):