[cubicweb/uwsgi] optionnal deploy of wsgi file (for looping tasks)
authorArthur Lutz <arthur.lutz@logilab.fr>
Wed, 14 Dec 2016 15:12:19 +0100
changeset 102 6a34a4eb10ad
parent 101 0f79a393517c
child 103 4ea00d8c15d1
[cubicweb/uwsgi] optionnal deploy of wsgi file (for looping tasks)
cubicweb/uwsgi/init.sls
cubicweb/uwsgi/uwsgi.ini
cubicweb/uwsgi/wsgiapp.py
pillar.example
--- a/cubicweb/uwsgi/init.sls	Wed Dec 14 15:11:31 2016 +0100
+++ b/cubicweb/uwsgi/init.sls	Wed Dec 14 15:12:19 2016 +0100
@@ -34,6 +34,15 @@
     - watch:
       - service: uwsgi
 
+{% if 'file' in  config.cwapp_uwsgi_options.keys() %}
+deploy wsgiapp.py for {{ name }}:
+  file.managed:
+    - name: {{ config.cwapp_uwsgi_options.file }}
+    - source: salt://cubicweb/uwsgi/wsgiapp.py
+    - template: jinja
+    - group: www-data
+{% endif %}
+
 /etc/cubicweb.d/{{ name }}/sources:
   file.managed:
     - group: www-data
--- a/cubicweb/uwsgi/uwsgi.ini	Wed Dec 14 15:11:31 2016 +0100
+++ b/cubicweb/uwsgi/uwsgi.ini	Wed Dec 14 15:12:19 2016 +0100
@@ -3,7 +3,11 @@
 http = 0.0.0.0:{{ config.cwapp.port|default('8080', true) }}
 env = CW_INSTANCE={{ name }}
 #env = CW_DEBUG=1
+{% if config.cwapp_uwsgi_options.file %}
+wsgi-file = {{ config.cwapp_uwsgi_options.file }}
+{% else %}
 module = cubicweb.pyramid:wsgi_application()
+{% endif %}
 processes = {{ config.cwapp_uwsgi_options.workers }}
 threads = {{ config.cwapp_uwsgi_options.threads }}
 plugins = http,python
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/uwsgi/wsgiapp.py	Wed Dec 14 15:12:19 2016 +0100
@@ -0,0 +1,15 @@
+import os
+from cubicweb.pyramid import wsgi_application_from_cwconfig
+from cubicweb.cwconfig import CubicWebConfiguration as cwcfg
+
+appid = os.environ['CW_INSTANCE']  # instance name
+
+cwconfig = cwcfg.config_for(appid)
+
+cwconfig.log_format = ('{0} pid:{1}'.format(appid, os.getpid()) +
+                               ' (%(name)s) %(levelname)s: %(message)s')
+
+application = wsgi_application_from_cwconfig(cwconfig,)
+repo = application.application.registry['cubicweb.repository']
+repo.start_looping_tasks()
+
--- a/pillar.example	Wed Dec 14 15:11:31 2016 +0100
+++ b/pillar.example	Wed Dec 14 15:12:19 2016 +0100
@@ -66,6 +66,7 @@
       cwapp_uwsgi_options:
         workers: 2
         threads: 8
+        #file: /etc/cubicweb.d/app/wsgiapp.py
       pyramid:
         sessions_secret: CHANGEME
         authtk_sessions_secret: CHANGEME