I have a process that when it gets a message it sends a command to a celery process. From there I would want to send back a message from the celery worker back to the backend telling it "Im done now you can continue". So can I send a group message to a channel layer from outside
edit should probably add some code example also:
consumer.py
async def startGame(self):
if self.leader:
songList = await self.getSongs()
await self.downloadSongs(songList)
tasks.py
@shared_task
def downloadSongs(songList, room_group_name):
from channels.layers import get_channel_layer
print(room_group_name)
for song in songList:
if not os.path.isfile("./songfiles/" + song["song_id"] + ".mp3"):
print("Downloading song: " + song["title"])
channel_layer = get_channel_layer()
print(channel_layer)
async_to_sync(channel_layer.group_send)(
room_group_name,
{
'type': 'startGameGroup',
})
print("Done sleeping")
consumer.py
async def startGameGroup(self, event):
await self.send(text_data=json.dumps({
"ContentType": "startGameGroup",
}))
so when startGame in consumer run it calls a celery task called downloadSongs. From there it should send back a message to the backend saying that it is done and it can start the game