diff --git a/app/YtManagerApp/management/jobs/synchronize.py b/app/YtManagerApp/management/jobs/synchronize.py index 11e49d4..376d980 100644 --- a/app/YtManagerApp/management/jobs/synchronize.py +++ b/app/YtManagerApp/management/jobs/synchronize.py @@ -4,7 +4,7 @@ from threading import Lock from apscheduler.triggers.cron import CronTrigger -from YtManagerApp import scheduler +from YtManagerApp.scheduler import scheduler from YtManagerApp.management.appconfig import appconfig from YtManagerApp.management.downloader import fetch_thumbnail, downloader_process_all, downloader_process_subscription from YtManagerApp.models import * @@ -150,15 +150,15 @@ def synchronize_subscription(subscription: Subscription): def schedule_synchronize_global(): trigger = CronTrigger.from_crontab(appconfig.sync_schedule) - job = scheduler.scheduler.add_job(synchronize, trigger, max_instances=1, coalesce=True) + job = scheduler.add_job(synchronize, trigger, max_instances=1, coalesce=True) log.info('Scheduled synchronize job job=%s', job.id) def schedule_synchronize_now(): - job = scheduler.scheduler.add_job(synchronize, max_instances=1, coalesce=True) + job = scheduler.add_job(synchronize, max_instances=1, coalesce=True) log.info('Scheduled synchronize now job job=%s', job.id) def schedule_synchronize_now_subscription(subscription: Subscription): - job = scheduler.scheduler.add_job(synchronize_subscription, args=[subscription]) + job = scheduler.add_job(synchronize_subscription, args=[subscription]) log.info('Scheduled synchronize subscription job subscription=(%s), job=%s', subscription, job.id) diff --git a/app/YtManagerApp/models.py b/app/YtManagerApp/models.py index 53ea3a7..93d3913 100644 --- a/app/YtManagerApp/models.py +++ b/app/YtManagerApp/models.py @@ -227,7 +227,7 @@ class Video(models.Model): schedule_delete_video(self) # Mark watched? - if appconfig.mark_deleted_as_watched: + if self.subscription.user.preferences['mark_deleted_as_watched']: self.watched = True schedule_synchronize_now_subscription(self.subscription) diff --git a/app/YtManagerApp/scheduler.py b/app/YtManagerApp/scheduler.py index 92514f9..74a8fdb 100644 --- a/app/YtManagerApp/scheduler.py +++ b/app/YtManagerApp/scheduler.py @@ -4,11 +4,10 @@ from apscheduler.schedulers.background import BackgroundScheduler from YtManagerApp.management.appconfig import appconfig -scheduler: BackgroundScheduler = None +scheduler = BackgroundScheduler() def initialize_scheduler(): - global scheduler logger = logging.getLogger('scheduler') executors = { @@ -21,5 +20,5 @@ def initialize_scheduler(): 'misfire_grace_time': 60 * 60 * 24 * 365 # 1 year } - scheduler = BackgroundScheduler(logger=logger, executors=executors, job_defaults=job_defaults) + scheduler.configure(logger=logger, executors=executors, job_defaults=job_defaults) scheduler.start()