[Django]-Django Channels 2.0: call Consumer's channel by its name

0👍

So based on your implementation, you are on the right track. You forgot to run the following


python manage.py runworker long-task

The print message would display there. More information is provided here https://channels.readthedocs.io/en/latest/topics/worker.html

👤gbozee

0👍

If after runworker, it’s still not working, see below.

The manual says:

Also remember that if you are sending the event from a synchronous environment, you have to use the asgiref.sync.async_to_sync wrapper as specified in channel layers.

So you should try this in your view:

async_to_sync(channel_layer.send)("long-task", {"type": "long.task", "text": 'Hey!'})
👤allan

Leave a comment