mirror of
https://github.com/django/daphne.git
synced 2025-07-03 19:33:14 +03:00
Make groups actually work
This commit is contained in:
parent
3a4847887e
commit
964c457df1
|
@ -17,4 +17,4 @@ from .hacks import monkeypatch_django
|
||||||
monkeypatch_django()
|
monkeypatch_django()
|
||||||
|
|
||||||
# Promote channel to top-level (down here to avoid circular import errs)
|
# Promote channel to top-level (down here to avoid circular import errs)
|
||||||
from .channel import Channel
|
from .channel import Channel, Group
|
||||||
|
|
|
@ -58,7 +58,7 @@ class Group(object):
|
||||||
of the group after an expiry time (keep re-adding to keep them in).
|
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
|
self.name = name
|
||||||
if channel_backend:
|
if channel_backend:
|
||||||
self.channel_backend = channel_backend
|
self.channel_backend = channel_backend
|
||||||
|
@ -66,13 +66,13 @@ class Group(object):
|
||||||
self.channel_backend = channel_backends[alias]
|
self.channel_backend = channel_backends[alias]
|
||||||
|
|
||||||
def add(self, channel):
|
def add(self, channel):
|
||||||
self.channel_backend.add(self.name, channel)
|
self.channel_backend.group_add(self.name, channel)
|
||||||
|
|
||||||
def discard(self, channel):
|
def discard(self, channel):
|
||||||
self.channel_backend.discard(self.name, channel)
|
self.channel_backend.group_discard(self.name, channel)
|
||||||
|
|
||||||
def channels(self):
|
def channels(self):
|
||||||
self.channel_backend.channels(self.name)
|
self.channel_backend.group_channels(self.name)
|
||||||
|
|
||||||
def send(self, **kwargs):
|
def send(self, **kwargs):
|
||||||
self.channel_backend.send_group(self, self.name, kwargs)
|
self.channel_backend.send_group(self.name, kwargs)
|
||||||
|
|
|
@ -5,10 +5,12 @@ from django.utils import six
|
||||||
from channels import channel_backends, DEFAULT_CHANNEL_BACKEND
|
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.
|
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
|
# Upconvert if you just pass in a string
|
||||||
if isinstance(channels, six.string_types):
|
if isinstance(channels, six.string_types):
|
||||||
channels = [channels]
|
channels = [channels]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user