annotate piecrust/serving/procloop.py @ 1043:54eb8ad9e809

serve: Use `watchdog` for a more efficient monitoring of assets files.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 20 Jan 2018 17:24:08 -0800
parents 89d94955b818
children 2f39ffa601a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
374
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 import os
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 import os.path
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 import time
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4 import json
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 import queue
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 import logging
552
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
7 import itertools
374
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 import threading
663
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 570
diff changeset
9 from piecrust import CONFIG_PATH, THEME_CONFIG_PATH
880
342e3ea24b5d serve: Fix asset processing loop.
Ludovic Chabant <ludovic@chabant.com>
parents: 876
diff changeset
10 from piecrust.chefutil import format_timed_scope
1037
89d94955b818 serve: Fix infinite loop in asset processing when a change is detected.
Ludovic Chabant <ludovic@chabant.com>
parents: 918
diff changeset
11 from piecrust.pipelines.records import MultiRecord
374
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 logger = logging.getLogger(__name__)
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15
552
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
16 # This flag is for cancelling all long running requests like SSEs.
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
17 server_shutdown = False
374
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19
552
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
20 class PipelineStatusServerSentEventProducer(object):
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
21 """ The producer for Server-Sent Events (SSE) notifying the front-end
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
22 about useful things like assets having been re-processed in the
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
23 background.
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
24 Each has its own queue because the user could have multiple pages
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
25 open, each having to display notifications coming from the server.
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
26 """
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
27 def __init__(self, proc_loop):
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
28 self._proc_loop = proc_loop
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
29 self._queue = queue.Queue()
374
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30 self._start_time = 0
552
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
31 self._poll_interval = 0.5
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
32 self._ping_interval = 30
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
33 self._time_between_pings = 0
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
34 self._running = 0
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
35
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
36 def addBuildEvent(self, item):
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
37 self._queue.put_nowait(item)
374
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 def run(self):
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 logger.debug("Starting pipeline status SSE.")
552
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
41 self._proc_loop.addObserver(self)
374
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 self._start_time = time.time()
552
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
43 self._running = 1
374
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45 outstr = 'event: ping\ndata: started\n\n'
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46 yield bytes(outstr, 'utf8')
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47
552
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
48 while self._running == 1 and not server_shutdown:
374
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49 try:
552
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
50 # We use a short poll interval (less than a second) because
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
51 # we need to catch `server_shutdown` going `True` as soon as
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
52 # possible to exit this thread when the user hits `CTRL+C`.
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
53 data = self._queue.get(True, self._poll_interval)
374
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54 except queue.Empty:
552
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
55 # Not exact timing but close enough.
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
56 self._time_between_pings += self._poll_interval
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
57 if self._time_between_pings >= self._ping_interval:
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
58 self._time_between_pings = 0
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
59 logger.debug("Sending ping/heartbeat event.")
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
60 outstr = 'event: ping\ndata: 1\n\n'
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
61 yield bytes(outstr, 'utf8')
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
62 continue
374
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
64 logger.debug("Sending pipeline status SSE.")
552
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
65 outstr = (('event: %s\n' % data['type']) +
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
66 ('id: %s\n' % data['id']) +
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
67 ('data: %s\n\n' % json.dumps(data)))
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
68 self._queue.task_done()
374
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
69 yield bytes(outstr, 'utf8')
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
70
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
71 def close(self):
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
72 logger.debug("Closing pipeline status SSE.")
552
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
73 self._proc_loop.removeObserver(self)
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
74 self._running = 2
374
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76
854
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 680
diff changeset
77 class _AssetProcessingInfo:
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 680
diff changeset
78 def __init__(self, source):
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 680
diff changeset
79 self.source = source
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 680
diff changeset
80 self.paths = set()
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 680
diff changeset
81 self.last_bake_time = time.time()
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 680
diff changeset
82
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 680
diff changeset
83
1043
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
84 class ProcessingLoopBase:
680
c2ea75e37540 serve: Fix some crashes introduced by recent refactor.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
85 def __init__(self, appfactory, out_dir):
666
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
86 self.appfactory = appfactory
680
c2ea75e37540 serve: Fix some crashes introduced by recent refactor.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
87 self.out_dir = out_dir
552
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
88 self.last_status_id = 0
854
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 680
diff changeset
89 self._app = None
552
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
90 self._obs = []
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
91 self._obs_lock = threading.Lock()
680
c2ea75e37540 serve: Fix some crashes introduced by recent refactor.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
92 config_name = (
854
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 680
diff changeset
93 THEME_CONFIG_PATH if appfactory.theme_site else CONFIG_PATH)
1043
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
94 self.config_path = os.path.join(appfactory.root_dir, config_name)
552
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
95
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
96 def addObserver(self, obs):
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
97 with self._obs_lock:
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
98 self._obs.append(obs)
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
99
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
100 def removeObserver(self, obs):
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
101 with self._obs_lock:
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
102 self._obs.remove(obs)
374
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
103
1043
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
104 def getApp(self):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
105 return self._app
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
106
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
107 def initialize(self):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
108 self._app = self.appfactory.create()
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
109 self.onInitialize()
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
110
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
111 def onInitialize(self):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
112 pass
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
113
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
114 def start(self):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
115 logger.info("Starting processing loop with output: %s" %
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
116 self.out_dir)
860
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
117 try:
1043
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
118 self.initialize()
860
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
119 except Exception as ex:
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
120 logger.error("Error initializing processing loop:")
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
121 logger.exception(ex)
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
122 return
570
7dabfdd056a1 serve: Fix corner cases where the pipeline doesn't run correctly.
Ludovic Chabant <ludovic@chabant.com>
parents: 565
diff changeset
123
860
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
124 logger.debug("Doing initial processing loop bake...")
1043
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
125 # self.runPipelines()
374
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
126
1043
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
127 self.onStart()
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
128
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
129 def onStart(self):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
130 raise NotImplementedError()
570
7dabfdd056a1 serve: Fix corner cases where the pipeline doesn't run correctly.
Ludovic Chabant <ludovic@chabant.com>
parents: 565
diff changeset
131
1043
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
132 def getSources(self):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
133 for src in self._app.sources:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
134 if src.config.get('pipeline') != 'asset':
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
135 continue
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
136 yield src
374
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
137
1043
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
138 def runPipelines(self, only_for_source=None):
918
7f1da7e7b154 internal: The processing loop for the server is now using the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 880
diff changeset
139 try:
1043
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
140 self._doRunPipelines(only_for_source)
918
7f1da7e7b154 internal: The processing loop for the server is now using the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 880
diff changeset
141 except Exception as ex:
7f1da7e7b154 internal: The processing loop for the server is now using the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 880
diff changeset
142 logger.error("Error while running asset pipeline:")
7f1da7e7b154 internal: The processing loop for the server is now using the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 880
diff changeset
143 logger.exception(ex)
7f1da7e7b154 internal: The processing loop for the server is now using the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 880
diff changeset
144
1043
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
145 def _doRunPipelines(self, only_for_source):
918
7f1da7e7b154 internal: The processing loop for the server is now using the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 880
diff changeset
146 from piecrust.baking.baker import Baker
570
7dabfdd056a1 serve: Fix corner cases where the pipeline doesn't run correctly.
Ludovic Chabant <ludovic@chabant.com>
parents: 565
diff changeset
147
918
7f1da7e7b154 internal: The processing loop for the server is now using the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 880
diff changeset
148 allowed_sources = None
7f1da7e7b154 internal: The processing loop for the server is now using the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 880
diff changeset
149 if only_for_source:
7f1da7e7b154 internal: The processing loop for the server is now using the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 880
diff changeset
150 allowed_sources = [only_for_source.name]
7f1da7e7b154 internal: The processing loop for the server is now using the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 880
diff changeset
151 baker = Baker(
7f1da7e7b154 internal: The processing loop for the server is now using the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 880
diff changeset
152 self.appfactory, self._app, self.out_dir,
7f1da7e7b154 internal: The processing loop for the server is now using the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 880
diff changeset
153 allowed_pipelines=['asset'],
7f1da7e7b154 internal: The processing loop for the server is now using the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 880
diff changeset
154 allowed_sources=allowed_sources,
7f1da7e7b154 internal: The processing loop for the server is now using the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 880
diff changeset
155 rotate_bake_records=False)
7f1da7e7b154 internal: The processing loop for the server is now using the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 880
diff changeset
156 records = baker.bake()
854
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 680
diff changeset
157
918
7f1da7e7b154 internal: The processing loop for the server is now using the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 880
diff changeset
158 self._onPipelinesRun(records)
570
7dabfdd056a1 serve: Fix corner cases where the pipeline doesn't run correctly.
Ludovic Chabant <ludovic@chabant.com>
parents: 565
diff changeset
159
918
7f1da7e7b154 internal: The processing loop for the server is now using the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 880
diff changeset
160 def _onPipelinesRun(self, records):
854
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 680
diff changeset
161 self.last_status_id += 1
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 680
diff changeset
162
918
7f1da7e7b154 internal: The processing loop for the server is now using the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 880
diff changeset
163 if records.success:
7f1da7e7b154 internal: The processing loop for the server is now using the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 880
diff changeset
164 for rec in records.records:
860
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
165 changed = filter(
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
166 lambda i: not i.was_collapsed_from_last_run,
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
167 rec.getEntries())
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
168 changed = itertools.chain.from_iterable(
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
169 map(lambda i: i.out_paths, changed))
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
170 changed = list(changed)
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
171 item = {
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
172 'id': self.last_status_id,
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
173 'type': 'pipeline_success',
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
174 'assets': changed}
374
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
175
860
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
176 self._notifyObservers(item)
854
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 680
diff changeset
177 else:
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 680
diff changeset
178 item = {
860
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
179 'id': self.last_status_id,
854
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 680
diff changeset
180 'type': 'pipeline_error',
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 680
diff changeset
181 'assets': []}
918
7f1da7e7b154 internal: The processing loop for the server is now using the baker.
Ludovic Chabant <ludovic@chabant.com>
parents: 880
diff changeset
182 for rec in records.records:
860
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
183 for entry in rec.getEntries():
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
184 if entry.errors:
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
185 asset_item = {
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
186 'path': entry.item_spec,
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
187 'errors': list(entry.errors)}
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
188 item['assets'].append(asset_item)
374
fa3ee8a8ee2d serve: Split the server code in a couple modules inside a `serving` package.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
189
860
c71472e6537f refactor: Get the processing loop in the server functional again.
Ludovic Chabant <ludovic@chabant.com>
parents: 855
diff changeset
190 self._notifyObservers(item)
854
08e02c2a2a1a core: Keep refactoring, this time to prepare for generator sources.
Ludovic Chabant <ludovic@chabant.com>
parents: 680
diff changeset
191
552
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
192 def _notifyObservers(self, item):
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
193 with self._obs_lock:
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
194 observers = list(self._obs)
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
195 for obs in observers:
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
196 obs.addBuildEvent(item)
9612cfc6455a serve: Rewrite of the Server-Sent Event code for build notifications.
Ludovic Chabant <ludovic@chabant.com>
parents: 374
diff changeset
197
1043
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
198
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
199 try:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
200 from watchdog.observers import Observer
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
201 from watchdog.events import FileSystemEventHandler
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
202 _has_watchdog = True
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
203 except ImportError:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
204 _has_watchdog = False
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
205
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
206
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
207 if _has_watchdog:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
208 class _AssetFileEventHandler(FileSystemEventHandler):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
209 def __init__(self, proc_loop, source):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
210 self._proc_loop = proc_loop
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
211 self._source = source
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
212
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
213 def on_any_event(self, event):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
214 if event.is_directory:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
215 return
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
216
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
217 pl = self._proc_loop
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
218 with pl._lock:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
219 pl._ops.append({
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
220 'op': 'bake',
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
221 'source': self._source,
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
222 'path': event.src_path,
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
223 'change': event.event_type,
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
224 'time': time.time()})
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
225 pl._event.set()
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
226
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
227
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
228 class _SiteConfigEventHandler(FileSystemEventHandler):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
229 def __init__(self, proc_loop, path):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
230 self._proc_loop = proc_loop
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
231 self._path = path
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
232
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
233 def on_modified(self, event):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
234 if event.src_path != self._path:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
235 return
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
236
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
237 pl = self._proc_loop
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
238 with pl._lock:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
239 pl._ops.append({'op': 'reinit'})
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
240 pl._event.set()
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
241
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
242
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
243 class WatchdogProcessingLoop(ProcessingLoopBase):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
244 def __init__(self, appfactory, out_dir):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
245 ProcessingLoopBase.__init__(self, appfactory, out_dir)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
246 self._op_thread = threading.Thread(
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
247 name='watchdog-operations',
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
248 target=self._runOpThread,
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
249 daemon=True)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
250 self._lock = threading.Lock()
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
251 self._event = threading.Event()
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
252 self._ops = []
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
253 self._last_op_time = 0
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
254
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
255 def onStart(self):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
256 logger.debug("Running watchdog monitor on:")
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
257 observer = Observer()
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
258
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
259 event_handler = _SiteConfigEventHandler(self, self.config_path)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
260 observer.schedule(event_handler, os.path.dirname(self.config_path))
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
261 logger.debug(" - %s" % self.config_path)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
262
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
263 for src in self.getSources():
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
264 path = getattr(src, 'fs_endpoint_path', None)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
265 if not path:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
266 logger.warn("Skipping source '%s' -- it doesn't have "
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
267 "a file-system endpoint." % src.name)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
268 continue
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
269 if not os.path.isdir(path):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
270 continue
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
271
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
272 logger.debug(" - %s" % path)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
273 event_handler = _AssetFileEventHandler(self, src)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
274 observer.schedule(event_handler, path, recursive=True)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
275
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
276 observer.start()
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
277 self._op_thread.start()
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
278
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
279 def _runOpThread(self):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
280 while not server_shutdown:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
281 try:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
282 self._event.wait()
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
283 with self._lock:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
284 ops = self._ops
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
285 self._ops = []
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
286 self._event.clear()
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
287
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
288 orig_len = len(ops)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
289 lot = self._last_op_time
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
290 ops = list(filter(lambda o: o['time'] > lot, ops))
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
291 logger.debug("Got %d ops, with %d that happened after "
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
292 "our last operation." % (orig_len, len(ops)))
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
293 if len(ops) == 0:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
294 continue
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
295
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
296 if any(filter(lambda o: o['op'] == 'reinit', ops)):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
297 logger.info("Site configuration changed, "
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
298 "reloading pipeline.")
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
299 self.initialize()
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
300 self.runPipelines()
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
301 continue
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
302
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
303 sources = set()
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
304 ops = list(filter(lambda o: o['op'] == 'bake', ops))
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
305 for op in ops:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
306 logger.info("Detected file-system change: "
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
307 "%s [%s]" %
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
308 (op['path'], op['change']))
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
309 sources.add(op['source'])
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
310
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
311 logger.debug("Processing: %s" % [s.name for s in sources])
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
312 for s in sources:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
313 self.runPipelines(s)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
314
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
315 self._last_op_time = time.time()
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
316
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
317 except (KeyboardInterrupt, SystemExit):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
318 break
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
319
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
320 ProcessingLoop = WatchdogProcessingLoop
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
321
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
322 else:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
323 class LegacyProcessingLoop(ProcessingLoopBase, threading.Thread):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
324 def __init__(self, appfactory, out_dir):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
325 ProcessingLoopBase.__init__(self, appfactory, out_dir)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
326 threading.Thread.__init__(self, name='pipeline-reloader',
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
327 daemon=True)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
328 self.interval = 1
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
329 self._proc_infos = None
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
330 self._last_config_mtime = 0
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
331
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
332 def onInitialize(self):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
333 self._proc_infos = {}
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
334 for src in self.getSources():
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
335 procinfo = _AssetProcessingInfo(src)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
336 self._proc_infos[src.name] = procinfo
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
337
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
338 # Build the list of initial asset files.
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
339 for item in src.getAllContents():
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
340 procinfo.paths.add(item.spec)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
341
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
342 def onStart(self):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
343 self._last_config_mtime = os.path.getmtime(self.config_path)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
344 threading.Thread.start(self)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
345
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
346 def run(self):
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
347 while True:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
348 cur_config_time = os.path.getmtime(self.config_path)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
349 if self._last_config_mtime < cur_config_time:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
350 logger.info("Site configuration changed, reloading pipeline.")
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
351 self._last_config_mtime = cur_config_time
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
352 self.initialize()
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
353 self.runPipelines()
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
354 continue
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
355
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
356 for procinfo in self._proc_infos.values():
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
357 # For each assets folder we try to find the first new or
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
358 # modified file. If any, we just run the pipeline on
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
359 # that source.
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
360 found_new_or_modified = False
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
361 for item in procinfo.source.getAllContents():
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
362 path = item.spec
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
363 if path not in procinfo.paths:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
364 logger.debug("Found new asset: %s" % path)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
365 procinfo.paths.add(path)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
366 found_new_or_modified = True
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
367 break
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
368 if os.path.getmtime(path) > procinfo.last_bake_time:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
369 logger.debug("Found modified asset: %s" % path)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
370 found_new_or_modified = True
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
371 break
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
372 if found_new_or_modified:
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
373 logger.info("change detected, reprocessed '%s'." %
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
374 procinfo.source.name)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
375 self.runPipelines(procinfo.source)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
376 procinfo.last_bake_time = time.time()
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
377
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
378 time.sleep(self.interval)
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
379
54eb8ad9e809 serve: Use `watchdog` for a more efficient monitoring of assets files.
Ludovic Chabant <ludovic@chabant.com>
parents: 1037
diff changeset
380 ProcessingLoop = LegacyProcessingLoop