Added sub-headings.
+====================================================
Using with Web Frameworks/WSGI/Message Queue Workers
====================================================
@@ -75,15 +76,13 @@ eventsourcing application class.
application = None
-Celery has a ``worker_process_init`` `signal
-<http://docs.celeryproject.org/en/latest/userguide/signals.html#worker-process-init>`__.
+Flask
+=====
+
Uwsgi has a ``@postfork`` `decorator
<http://uwsgi-docs.readthedocs.io/en/latest/PythonDecorators.html#uwsgidecorators.postfork>`__
that can be used with Django and Flask and other frameworks.
-
-
-
Example Flask application.
.. code:: python
@@ -109,35 +108,14 @@ Example Flask application.
return "Hello World"
-Example Celery worker.
-
-.. code:: python
-
- from celery import Celery
- from celery.signals import worker_process_init
-
- app = Celery()
-
- @worker_process_init.connect
- def init_process(sender=None, conf=None, **kwargs):
- # Setup database connection for this process.
- # ...
-
- # Construct eventsourcing application for this process.
- init_application()
-
- @app.task
- def hello_world():
- # Use eventsourcing application to construct response to request.
- app = get_application()
- return "Hello World"
-
+Django
+======
-Example .wsgi file for a Django project.
+Example .wsgi file for a Django project, using the uWSGI ``postfork`` decorator.
.. code:: python
- from django.core.wsgi import get_wsgi_application # noqa
+ from django.core.wsgi import get_wsgi_application
from uwsgidecorators import postfork
application = get_wsgi_application()
@@ -159,3 +137,33 @@ Example Django view.
app = get_application()
html = "<html><body>Hello world</body></html>"
return HttpResponse(html)
+
+
+Celery
+======
+
+Celery has a ``worker_process_init`` `signal
+<http://docs.celeryproject.org/en/latest/userguide/signals.html#worker-process-init>`__.
+
+Example Celery worker.
+
+.. code:: python
+
+ from celery import Celery
+ from celery.signals import worker_process_init
+
+ app = Celery()
+
+ @worker_process_init.connect
+ def init_process(sender=None, conf=None, **kwargs):
+ # Setup database connection for this process.
+ # ...
+
+ # Construct eventsourcing application for this process.
+ init_application()
+
+ @app.task
+ def hello_world():
+ # Use eventsourcing application to construct response to request.
+ app = get_application()
+ return "Hello World"
