comparison piecrust/serving/procloop.py @ 666:81d9c3a3a0b5

internal: Get rid of the whole "sub cache" business. * Compute cache keys up front, so the cache directory is only chosen once. * Buffer up config variants to apply before loading the config. Makes it possible to cache variant-resulting configs, too. * Make a factory class to reuse the logic that creates the `PieCrust` object correctly for multi-process workers and such. * Add a test.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 03 Mar 2016 08:22:41 -0800
parents 3ceeca7bb71c
children c2ea75e37540
comparison
equal deleted inserted replaced
665:5dc13c816045 666:81d9c3a3a0b5
73 self._proc_loop.removeObserver(self) 73 self._proc_loop.removeObserver(self)
74 self._running = 2 74 self._running = 2
75 75
76 76
77 class ProcessingLoop(threading.Thread): 77 class ProcessingLoop(threading.Thread):
78 def __init__(self, root_dir, out_dir, sub_cache_dir=None, 78 def __init__(self, appfactory):
79 theme_site=False, debug=False):
80 super(ProcessingLoop, self).__init__( 79 super(ProcessingLoop, self).__init__(
81 name='pipeline-reloader', daemon=True) 80 name='pipeline-reloader', daemon=True)
82 self.root_dir = root_dir 81 self.appfactory = appfactory
83 self.out_dir = out_dir
84 self.sub_cache_dir = sub_cache_dir
85 self.debug = debug
86 self.theme_site = theme_site
87 self.last_status_id = 0 82 self.last_status_id = 0
88 self.interval = 1 83 self.interval = 1
89 self.app = None 84 self.app = None
90 self._roots = [] 85 self._roots = []
91 self._monitor_assets_root = False 86 self._monitor_assets_root = False
93 self._record = None 88 self._record = None
94 self._last_bake = 0 89 self._last_bake = 0
95 self._last_config_mtime = 0 90 self._last_config_mtime = 0
96 self._obs = [] 91 self._obs = []
97 self._obs_lock = threading.Lock() 92 self._obs_lock = threading.Lock()
98 if theme_site: 93 if appfactory.theme_site:
99 self._config_path = os.path.join(root_dir, THEME_CONFIG_PATH) 94 self._config_path = os.path.join(root_dir, THEME_CONFIG_PATH)
100 else: 95 else:
101 self._config_path = os.path.join(root_dir, CONFIG_PATH) 96 self._config_path = os.path.join(root_dir, CONFIG_PATH)
102 97
103 def addObserver(self, obs): 98 def addObserver(self, obs):
160 155
161 time.sleep(self.interval) 156 time.sleep(self.interval)
162 157
163 def _initPipeline(self): 158 def _initPipeline(self):
164 # Create the app and pipeline. 159 # Create the app and pipeline.
165 self.app = PieCrust(root_dir=self.root_dir, debug=self.debug, 160 self.app = self.appfactory.create()
166 theme_site=self.theme_site)
167 if self.sub_cache_dir:
168 self.app._useSubCacheDir(self.sub_cache_dir)
169 self.pipeline = ProcessorPipeline(self.app, self.out_dir) 161 self.pipeline = ProcessorPipeline(self.app, self.out_dir)
170 162
171 # Get the list of assets directories. 163 # Get the list of assets directories.
172 self._roots = list(self.pipeline.mounts.keys()) 164 self._roots = list(self.pipeline.mounts.keys())
173 165