Commit f56b36ae authored by echel0n's avatar echel0n

Added function to configure dogpile cache regions on startup, replace region on backup restores.

parent 32e77cdb
......@@ -44,7 +44,7 @@ from tornado.ioloop import IOLoop
import sickrage
from sickrage.core.announcements import Announcements
from sickrage.core.api import API
from sickrage.core.caches import tv_episodes_cache, MutexLock
from sickrage.core.caches import tv_episodes_cache, MutexLock, configure_regions
from sickrage.core.caches.name_cache import NameCache
from sickrage.core.caches.quicksearch_cache import QuicksearchCache
from sickrage.core.common import SD, SKIPPED, WANTED
......@@ -184,9 +184,6 @@ class Core(object):
# thread name
threading.currentThread().setName('CORE')
tv_episodes_cache.configure('dogpile.cache.dbm', replace_existing_backend=False,
arguments={'filename': os.path.join(self.cache_dir, 'tv_episodes.dbm'), 'lock_factory': MutexLock})
# init core classes
self.api = API()
self.main_db = MainDB(self.db_type, self.db_prefix, self.db_host, self.db_port, self.db_username, self.db_password)
......@@ -239,7 +236,10 @@ class Core(object):
if success:
self.main_db = MainDB(self.db_type, self.db_prefix, self.db_host, self.db_port, self.db_username, self.db_password)
self.cache_db = CacheDB(self.db_type, self.db_prefix, self.db_host, self.db_port, self.db_username, self.db_password)
configure_regions(self.cache_dir, replace_existing_backend=True)
shutil.rmtree(os.path.abspath(os.path.join(self.data_dir, 'restore')), ignore_errors=True)
else:
configure_regions(self.cache_dir)
# migrate old database file names to new ones
if os.path.isfile(os.path.abspath(os.path.join(self.data_dir, 'sickbeard.db'))):
......@@ -572,11 +572,13 @@ class Core(object):
show = TVShow(show.indexer_id, show.indexer)
self.shows.update({(show.indexer_id, show.indexer): show})
show.episodes()
except Exception:
except Exception as e:
self.log.debug('There was an error loading show: {}'.format(show.name))
self.loading_shows = False
self.log.info('Loading initial shows list finished')
def shutdown(self, restart=False):
if self.started:
self.log.info('SiCKRAGE IS SHUTTING DOWN!!!')
......
import os
from dogpile.cache import make_region
from dogpile.cache.backends.file import AbstractFileLock
from dogpile.util import ReadWriteMutex
......@@ -43,4 +45,9 @@ def region_key_generator(namespace, fn):
return generate_keys
def configure_regions(cache_dir, replace_existing_backend=False):
tv_episodes_cache.configure('dogpile.cache.dbm', replace_existing_backend=replace_existing_backend,
arguments={'filename': os.path.join(cache_dir, 'tv_episodes.dbm'), 'lock_factory': MutexLock})
tv_episodes_cache = make_region(function_key_generator=region_key_generator)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment