Coverage for gws-app/gws/server/spool/wsgi_app.py: 0%
28 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
1"""Spool server application."""
3import gws
4import gws.config
5import gws.server.uwsgi_module
7from . import runner
10def application(environ, start_response):
11 """WSGI application of the spool server, which does nothing.
13 Args:
14 environ: WSGI environment.
15 start_response: WSGI ``start_response`` callable.
16 """
17 pass
20def spooler(env):
21 """Run a queued job, called by the uWSGI spooler.
23 Errors are logged, the job is never retried by the spooler.
25 Args:
26 env: Spooler arguments.
28 Returns:
29 The uWSGI ``SPOOL_OK`` code, so the spooler removes the task.
30 """
31 try:
32 runner.run(gws.get_root(), env)
33 except:
34 gws.log.exception()
36 # even if it's failed, return OK so the spooler can clean up
37 # if we ever provide retry, this will on the app level, no automatic spooler retries
38 return runner.OK
41def init():
42 """Initialize the spool server.
44 Loads the stored configuration, installs the spooler callback, sets the log level
45 and starts the monitor if ``server.withMonitor`` is set. Exits the process with code 1 on errors.
46 """
47 root = None
49 try:
50 gws.log.info('starting SPOOL application')
51 root = gws.config.load()
52 except:
53 gws.log.exception('UNABLE TO LOAD CONFIGURATION')
54 gws.u.exit(1)
56 gws.server.uwsgi_module.load().spooler = spooler
58 try:
59 gws.log.set_level(root.app.cfg('server.log.level'))
60 if root.app.cfg('server.withMonitor'):
61 root.app.monitor.start()
62 except:
63 gws.log.exception('SPOOL INIT ERROR')
64 gws.u.exit(1)