Using Django Channels for a progress indicator -


i have django app carries out calculations on server can take 30 seconds. trying use django channels create progress indicator.

my setup based on tutorial: https://realpython.com/blog/python/getting-started-with-django-channels/

everything working expected far. submit task web socket. received consumer, calls other methods complete task, returns result websocket.

however, when try send multiple messages same consumer, messages arrive @ end, rather arriving when sent.

here consumer code:

@channel_session def ws_receive(message):     data = json.loads(message['text'])     reply_channel = message.reply_channel.name      channel(reply_channel).send({         "text": json.dumps({'progress': 'starting work'})     })            # calls outside method work     result = perform_calculations(data, reply_channel)      channel(reply_channel).send({         "text": json.dumps({'progress': 'finished work','result':result })     })   

in example, front end receives 'starting work' , 'finished work' messages @ same time, though there 30 second gap between them being generated.

is there way these messages arrive in real time?

yes there is, use parameter.

channel(message.reply_channel).send({     "text": json.dumps({'progress': 'starting work'}) }, immediately=true) 

also mentioned at:

how ensure django channels message sent without delay?


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -