Hi everyone,
The idea is to run a background task on the worker.connect
worker. While executing the task, I would like to send its progress to a connected client via the notifications Group.
The problem: the messages sent to the notifications Group are delayed until the task on the worker is finished. So: both messages 'Start' and 'Stop' appear simultaneously on the client, after a delay of 5 seconds (sleep(5)
). I would expect the message 'Start', followed by a 5sec delay, followed by the message 'Stop'. Any idea why this is not the case?
I have the following three processes running:
In views.py
:
def run(request, pk):
Channel('worker.connect').send({'pk': pk})
return HttpResponse(status=200)
In consumers.py
:
def ws_connect(message):
Group('notifications').add(message.reply_channel)
message.reply_channel.send({"accept": True})
def worker_connect(message):
run_channel(message)
In views.py
:
def run_channel(message):
Group('notifications').send({'text': 'Start'})
sleep(5)
Group('notifications').send({'text': 'Stop'})
routing.py
channel_routing = {
'websocket.connect': consumers.ws_connect,
'worker.connect': consumers.worker_connect,
}
--E-mail: inghelbrecht.joren@gmail.com
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/92b30e17-ebaa-4121-b5cf-7fc8c657498c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.