comparison piecrust/baking/baker.py @ 453:8351a77e13f5

bake: Don't pass the previous record entries to the workers. Workers now load the previous record on their own and find the previous entry in their own copy.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 07 Jul 2015 20:19:54 -0700
parents 838f3964f400
children 5e902e228053
comparison
equal deleted inserted replaced
452:55026b7bb1bf 453:8351a77e13f5
70 record.loadPrevious(previous_record_path) 70 record.loadPrevious(previous_record_path)
71 record.current.success = True 71 record.current.success = True
72 72
73 # Figure out if we need to clean the cache because important things 73 # Figure out if we need to clean the cache because important things
74 # have changed. 74 # have changed.
75 self._handleCacheValidity(record) 75 is_cache_valid = self._handleCacheValidity(record)
76 if not is_cache_valid:
77 previous_record_path = None
76 78
77 # Pre-create all caches. 79 # Pre-create all caches.
78 for cache_name in ['app', 'baker', 'pages', 'renders']: 80 for cache_name in ['app', 'baker', 'pages', 'renders']:
79 self.app.cache.getCache(cache_name) 81 self.app.cache.getCache(cache_name)
80 82
86 for source in self.app.sources: 88 for source in self.app.sources:
87 srclist = sources_by_realm.setdefault(source.realm, []) 89 srclist = sources_by_realm.setdefault(source.realm, [])
88 srclist.append(source) 90 srclist.append(source)
89 91
90 # Create the worker processes. 92 # Create the worker processes.
91 pool = self._createWorkerPool() 93 pool = self._createWorkerPool(previous_record_path)
92 94
93 # Bake the realms. 95 # Bake the realms.
94 realm_list = [REALM_USER, REALM_THEME] 96 realm_list = [REALM_USER, REALM_THEME]
95 for realm in realm_list: 97 for realm in realm_list:
96 srclist = sources_by_realm.get(realm) 98 srclist = sources_by_realm.get(realm)
177 record.incremental_count = 0 179 record.incremental_count = 0
178 record.clearPrevious() 180 record.clearPrevious()
179 logger.info(format_timed( 181 logger.info(format_timed(
180 start_time, 182 start_time,
181 "cleaned cache (reason: %s)" % reason)) 183 "cleaned cache (reason: %s)" % reason))
184 return False
182 else: 185 else:
183 record.incremental_count += 1 186 record.incremental_count += 1
184 logger.debug(format_timed( 187 logger.debug(format_timed(
185 start_time, "cache is assumed valid", 188 start_time, "cache is assumed valid",
186 colored=False)) 189 colored=False))
190 return True
187 191
188 def _bakeRealm(self, record, pool, realm, srclist): 192 def _bakeRealm(self, record, pool, realm, srclist):
189 start_time = time.perf_counter() 193 start_time = time.perf_counter()
190 try: 194 try:
191 record.current.baked_count[realm] = 0 195 record.current.baked_count[realm] = 0
509 'type': JOB_BAKE, 513 'type': JOB_BAKE,
510 'job': { 514 'job': {
511 'factory_info': save_factory(fac), 515 'factory_info': save_factory(fac),
512 'taxonomy_info': tax_info, 516 'taxonomy_info': tax_info,
513 'route_metadata': route_metadata, 517 'route_metadata': route_metadata,
514 'prev_entry': prev_entry,
515 'dirty_source_names': record.dirty_source_names 518 'dirty_source_names': record.dirty_source_names
516 } 519 }
517 } 520 }
518 return job 521 return job
519 522
533 rel_path = os.path.relpath(path, self.app.root_dir) 536 rel_path = os.path.relpath(path, self.app.root_dir)
534 logger.error("Errors found in %s:" % rel_path) 537 logger.error("Errors found in %s:" % rel_path)
535 for e in errors: 538 for e in errors:
536 logger.error(" " + e) 539 logger.error(" " + e)
537 540
538 def _createWorkerPool(self): 541 def _createWorkerPool(self, previous_record_path):
539 from piecrust.workerpool import WorkerPool 542 from piecrust.workerpool import WorkerPool
540 from piecrust.baking.worker import BakeWorkerContext, BakeWorker 543 from piecrust.baking.worker import BakeWorkerContext, BakeWorker
541 544
542 ctx = BakeWorkerContext( 545 ctx = BakeWorkerContext(
543 self.app.root_dir, self.app.cache.base_dir, self.out_dir, 546 self.app.root_dir, self.app.cache.base_dir, self.out_dir,
547 previous_record_path=previous_record_path,
544 force=self.force, debug=self.app.debug) 548 force=self.force, debug=self.app.debug)
545 pool = WorkerPool( 549 pool = WorkerPool(
546 worker_class=BakeWorker, 550 worker_class=BakeWorker,
547 initargs=(ctx,)) 551 initargs=(ctx,))
548 return pool 552 return pool