Warn when trying to use runworker with in memory layer

This commit is contained in:
Andrew Godwin 2016-02-28 21:52:35 -08:00
parent b18975e607
commit 61b8940e99
2 changed files with 11 additions and 1 deletions

View File

@ -75,6 +75,10 @@ class ChannelLayerWrapper(object):
def __str__(self):
return "%s (%s)" % (self.alias, name_that_thing(self.channel_layer))
def local_only(self):
# TODO: Can probably come up with a nicer check?
return "inmemory" in self.channel_layer.__class__.__module__
def get_channel_layer(alias="default"):
"""

View File

@ -1,6 +1,6 @@
from __future__ import unicode_literals
from django.core.management import BaseCommand
from django.core.management import BaseCommand, CommandError
from channels import channel_layers, DEFAULT_CHANNEL_LAYER
from channels.log import setup_logger
from channels.worker import Worker
@ -13,6 +13,12 @@ class Command(BaseCommand):
self.verbosity = options.get("verbosity", 1)
self.logger = setup_logger('django.channels', self.verbosity)
self.channel_layer = channel_layers[DEFAULT_CHANNEL_LAYER]
# Check that handler isn't inmemory
if self.channel_layer.local_only():
raise CommandError(
"You cannot span multiple processes with the in-memory layer. " +
"Change your settings to use a cross-process channel layer."
)
# Check a handler is registered for http reqs
self.channel_layer.registry.check_default()
# Launch a worker