Fixed 2 bugs: fixed exception where imported scheduler is 'None'. Fixed exception that mark_deleted_as_watched is not found (it is an user preference, not a global preference).

This commit is contained in:
Tiberiu Chibici 2018-12-30 14:45:42 +02:00
parent 457b0c4dc9
commit 070755f119
3 changed files with 7 additions and 8 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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()