S
S
Ska1n2015-02-23 03:02:41
JavaScript
Ska1n, 2015-02-23 03:02:41

How to monitor process execution in real time via ajax?

Good afternoon. The essence is this: through ajax I send a command to the server to perform some action, say, generating a bunch of pictures, how best to implement monitoring of the progress of the script? For example, to display in real time how much more percentage to execute the script and, if necessary, stop its execution? Front and backend - in python dzhangovsky.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
D
devel787, 2015-02-25
@devel787

Maybe blog.miguelgrinberg.com/post/using-celery-with-flask can help

N
Nikolai Sheregeda, 2015-03-01
@Sheregeda

Run the process in celery , there you can cancel the task if necessary. There is integration with Django .
The message can be organized through centrifuge . On the client, we subscribe to the channel, on the backend we write to it. On Habré there are articles about centrifuge
But this is a hardcore scheme and with some overhead)

X
xmoonlight, 2015-02-23
@xmoonlight

fork the process with the database update - read the parameter for ajax-a from there.
with each update - check for the command: appeared - execute.
database table for understanding:
ID,script_name,status,completed,command

L
lnked, 2015-02-23
@lnked

let's say you have 100 pictures, so for 100% of the time we need to process 100 images at 1 percent per image
in js, we write a function that sends a request to the server and, upon returning the response, increases the progress bar by 1 percent, and calls itself as soon as we reach up to 100% we stop calling ourselves and everything is ready
so that the essence is clear

S
Sergey Romanov, 2015-02-23
@Serhioromano

It's usually done like this. You send a request to process images to the server. There you estimate the time of work approximately. Then you create a worker/process.json file and put {done:0} there which means 0%.
Now in your javascript, immediately after starting Ajax, run setInterval b every 200ms, read this file and use its value for the progress bar.
And when ajax finishes, interrupt setInterval and set the progress bar to 100%.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question