Mercurial > piecrust2
comparison piecrust/processing/worker.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 | 61d606fbc313 |
comparison
equal
deleted
inserted
replaced
665:5dc13c816045 | 666:81d9c3a3a0b5 |
---|---|
1 import re | 1 import re |
2 import os.path | 2 import os.path |
3 import time | 3 import time |
4 import logging | 4 import logging |
5 from piecrust.app import PieCrust | 5 from piecrust.app import PieCrust, apply_variant_and_values |
6 from piecrust.processing.base import PipelineContext | 6 from piecrust.processing.base import PipelineContext |
7 from piecrust.processing.records import ( | 7 from piecrust.processing.records import ( |
8 FLAG_NONE, FLAG_PREPARED, FLAG_PROCESSED, | 8 FLAG_NONE, FLAG_PREPARED, FLAG_PROCESSED, |
9 FLAG_BYPASSED_STRUCTURED_PROCESSING) | 9 FLAG_BYPASSED_STRUCTURED_PROCESSING) |
10 from piecrust.processing.tree import ( | 10 from piecrust.processing.tree import ( |
21 split_processor_names_re = re.compile(r'[ ,]+') | 21 split_processor_names_re = re.compile(r'[ ,]+') |
22 re_ansicolors = re.compile('\033\\[\d+m') | 22 re_ansicolors = re.compile('\033\\[\d+m') |
23 | 23 |
24 | 24 |
25 class ProcessingWorkerContext(object): | 25 class ProcessingWorkerContext(object): |
26 def __init__(self, root_dir, out_dir, tmp_dir, *, | 26 def __init__(self, appfactory, out_dir, tmp_dir, *, |
27 force=False, debug=False, theme_site=False): | 27 force=False): |
28 self.root_dir = root_dir | 28 self.appfactory = appfactory |
29 self.out_dir = out_dir | 29 self.out_dir = out_dir |
30 self.tmp_dir = tmp_dir | 30 self.tmp_dir = tmp_dir |
31 self.force = force | 31 self.force = force |
32 self.debug = debug | |
33 self.theme_site = theme_site | |
34 self.is_profiling = False | 32 self.is_profiling = False |
35 self.enabled_processors = None | 33 self.enabled_processors = None |
36 self.additional_processors = None | 34 self.additional_processors = None |
37 | 35 |
38 | 36 |
58 self.ctx = ctx | 56 self.ctx = ctx |
59 self.work_start_time = time.perf_counter() | 57 self.work_start_time = time.perf_counter() |
60 | 58 |
61 def initialize(self): | 59 def initialize(self): |
62 # Create the app local to this worker. | 60 # Create the app local to this worker. |
63 app = PieCrust(self.ctx.root_dir, debug=self.ctx.debug, | 61 app = self.ctx.appfactory.create() |
64 theme_site=self.ctx.theme_site) | |
65 app.env.registerTimer("PipelineWorker_%d_Total" % self.wid) | 62 app.env.registerTimer("PipelineWorker_%d_Total" % self.wid) |
66 app.env.registerTimer("PipelineWorkerInit") | 63 app.env.registerTimer("PipelineWorkerInit") |
67 app.env.registerTimer("JobReceive") | 64 app.env.registerTimer("JobReceive") |
68 app.env.registerTimer('BuildProcessingTree') | 65 app.env.registerTimer('BuildProcessingTree') |
69 app.env.registerTimer('RunProcessingTree') | 66 app.env.registerTimer('RunProcessingTree') |