DjangoChannels: How send message to groups on AsyncJsonWebsocketConsumer.disconnect()?

110 views
Skip to first unread message

Vladimir Kalyuzhny

unread,
Oct 19, 2020, 1:57:57 PM10/19/20
to Django users

Please suggest to me a workaround on how to send message to groups on AsyncJsonWebsocketConsumer.disconnect()?

class UserConsumer(AsyncJsonWebsocketConsumer):
    ... // some code

    async def disconnect(self, close_code: str) -> None:

        channel_layer = get_channel_layer()

        await channel_layer.group_send(
            "some_group", {"type": "send_message", "message": "some test message"},
        )

This is a simple example of my code. When I do this, I've got error:

File "/home/user/.pyenv/versions/3.8.6/envs/venv38/lib/python3.8/site-packages/channels_redis/core.py", line 666, in group_send await connection.zremrangebyscore( aioredis.errors.ConnectionForcedCloseError

I think, disconnect() method is not the best place to send messages. If yes, what is a good place for this?

Some useful links:


Reply all
Reply to author
Forward
0 new messages