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

1"""Spool server application.""" 

2 

3import gws 

4import gws.config 

5import gws.server.uwsgi_module 

6 

7from . import runner 

8 

9 

10def application(environ, start_response): 

11 """WSGI application of the spool server, which does nothing. 

12 

13 Args: 

14 environ: WSGI environment. 

15 start_response: WSGI ``start_response`` callable. 

16 """ 

17 pass 

18 

19 

20def spooler(env): 

21 """Run a queued job, called by the uWSGI spooler. 

22 

23 Errors are logged, the job is never retried by the spooler. 

24 

25 Args: 

26 env: Spooler arguments. 

27 

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() 

35 

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 

39 

40 

41def init(): 

42 """Initialize the spool server. 

43 

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 

48 

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) 

55 

56 gws.server.uwsgi_module.load().spooler = spooler 

57 

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) 

65