#196: made worker serve staticfiles if DEBUG=True (#197)

This commit is contained in:
thewayiam 2016-06-06 13:06:37 +08:00 committed by Andrew Godwin
parent 6eaee8f522
commit 18d4cc8e6f
2 changed files with 8 additions and 1 deletions

View File

@ -1,10 +1,12 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf import settings
from django.core.management import BaseCommand, CommandError from django.core.management import BaseCommand, CommandError
from channels import DEFAULT_CHANNEL_LAYER, channel_layers from channels import DEFAULT_CHANNEL_LAYER, channel_layers
from channels.log import setup_logger from channels.log import setup_logger
from channels.worker import Worker from channels.worker import Worker
from channels.staticfiles import StaticFilesConsumer
class Command(BaseCommand): class Command(BaseCommand):
@ -38,7 +40,11 @@ class Command(BaseCommand):
"Change your settings to use a cross-process channel layer." "Change your settings to use a cross-process channel layer."
) )
# Check a handler is registered for http reqs # Check a handler is registered for http reqs
self.channel_layer.router.check_default() # Serve static files if Django in debug mode
if settings.DEBUG:
self.channel_layer.router.check_default(http_consumer=StaticFilesConsumer())
else:
self.channel_layer.router.check_default()
# Launch a worker # Launch a worker
self.logger.info("Running worker against channel layer %s", self.channel_layer) self.logger.info("Running worker against channel layer %s", self.channel_layer)
# Optionally provide an output callback # Optionally provide an output callback

View File

@ -320,6 +320,7 @@ As you can probably guess, this disables the worker threads in ``runserver``
and handles them in a separate process. You can pass ``-v 2`` to ``runworker`` and handles them in a separate process. You can pass ``-v 2`` to ``runworker``
if you want to see logging as it runs the consumers. if you want to see logging as it runs the consumers.
If Django in debug mode(`DEBUG=True`), it'll serve static files as Django default behavior.
Persisting Data Persisting Data
--------------- ---------------