Make groups actually work

This commit is contained in:
Andrew Godwin 2015-07-12 23:52:02 -05:00
parent 3a4847887e
commit 964c457df1
3 changed files with 9 additions and 7 deletions

View File

@ -17,4 +17,4 @@ from .hacks import monkeypatch_django
monkeypatch_django()
# Promote channel to top-level (down here to avoid circular import errs)
from .channel import Channel
from .channel import Channel, Group

View File

@ -58,7 +58,7 @@ class Group(object):
of the group after an expiry time (keep re-adding to keep them in).
"""
def __init__(self, alias=DEFAULT_CHANNEL_BACKEND, channel_backend=None):
def __init__(self, name, alias=DEFAULT_CHANNEL_BACKEND, channel_backend=None):
self.name = name
if channel_backend:
self.channel_backend = channel_backend
@ -66,13 +66,13 @@ class Group(object):
self.channel_backend = channel_backends[alias]
def add(self, channel):
self.channel_backend.add(self.name, channel)
self.channel_backend.group_add(self.name, channel)
def discard(self, channel):
self.channel_backend.discard(self.name, channel)
self.channel_backend.group_discard(self.name, channel)
def channels(self):
self.channel_backend.channels(self.name)
self.channel_backend.group_channels(self.name)
def send(self, **kwargs):
self.channel_backend.send_group(self, self.name, kwargs)
self.channel_backend.send_group(self.name, kwargs)

View File

@ -5,10 +5,12 @@ from django.utils import six
from channels import channel_backends, DEFAULT_CHANNEL_BACKEND
def consumer(self, alias=DEFAULT_CHANNEL_BACKEND, *channels):
def consumer(*channels, **kwargs):
"""
Decorator that registers a function as a consumer.
"""
# We can't put a kwarg after *args in py2
alias = kwargs.get("alias", DEFAULT_CHANNEL_BACKEND)
# Upconvert if you just pass in a string
if isinstance(channels, six.string_types):
channels = [channels]