comparison foodtruck/pubutil.py @ 772:3885421c29a3

admin: Make the whole FoodTruck site into a blueprint. This makes it possible to use an app factory, which makes it easier to write unit tests.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 03 Jul 2016 07:54:54 -0700
parents 65706804e1de
children 3799621cd25b
comparison
equal deleted inserted replaced
771:673979a5d548 772:3885421c29a3
2 import os.path 2 import os.path
3 import time 3 import time
4 import errno 4 import errno
5 import signal 5 import signal
6 import logging 6 import logging
7 from .web import app 7 from .blueprint import foodtruck_bp
8 8
9 9
10 logger = logging.getLogger(__name__) 10 logger = logging.getLogger(__name__)
11 11
12 server_shutdown = False 12 server_shutdown = False
13 13
14 14
15 def _shutdown_server_and_raise_sigint(): 15 def _shutdown_server_and_raise_sigint(is_app_debug):
16 if not app.debug or os.environ.get('WERKZEUG_RUN_MAIN') == 'true': 16 if (not is_app_debug or
17 os.environ.get('WERKZEUG_RUN_MAIN') == 'true'):
17 # This is needed when hitting CTRL+C to shutdown the Werkzeug server, 18 # This is needed when hitting CTRL+C to shutdown the Werkzeug server,
18 # otherwise SSE generators will keep it alive. 19 # otherwise SSE generators will keep it alive.
19 logger.debug("Shutting down SSE generators...") 20 logger.debug("Shutting down SSE generators...")
21 logger.flush()
20 global server_shutdown 22 global server_shutdown
21 server_shutdown = True 23 server_shutdown = True
22 raise KeyboardInterrupt() 24 raise KeyboardInterrupt()
23 25
24 26
25 if app.config.get('FOODTRUCK_CMDLINE_MODE', False): 27 def record_pipeline(state):
26 # Make sure CTRL+C works correctly. 28 if state.app.config.get('FOODTRUCK_CMDLINE_MODE', False):
27 signal.signal(signal.SIGINT, 29 # Make sure CTRL+C works correctly.
28 lambda *args: _shutdown_server_and_raise_sigint()) 30 logger.debug("Adding SIGINT callback for pipeline thread.")
31 signal.signal(
32 signal.SIGINT,
33 lambda *args: _shutdown_server_and_raise_sigint(
34 state.app.debug))
35
36
37 foodtruck_bp.record(record_pipeline)
29 38
30 39
31 def _read_pid_file(pid_file): 40 def _read_pid_file(pid_file):
32 logger.debug("Reading PID file: %s" % pid_file) 41 logger.debug("Reading PID file: %s" % pid_file)
33 try: 42 try: