Progress bar with long web requests

In the django application I'm working on, I just added the ability to archive multiple files (starting at 50 mb) into a zip file. I am currently doing it something like this:

get files to zip
zip all files
send HTML response

Obviously, this leads to a lot of waiting on line 2, where the files are compressed. What can I do to make this process much better for the user? Although having a progress indicator would be better, even if it just returned a static page that says "please wait" or something else.

Any thoughts and ideas will be loved.

+3
source share
4 answers

, , - .

zip , - - , , - .

django-lineup

:

from lineup import registry
from lineup import _debug

def create_archive(queue_id, queue):
    queue.set_param("zip_link", _create_archive(resource = queue.context_object, user = queue.user))
    return queue


def create_archive_callback(queue_id, queue):
    _send_email_notification(subject = queue.get_param("zip_link"), user = queue.user)
    return queue

registry.register_job('create_archive', create_archive, callback = create_archive_callback)

:

    from lineup.factory import JobFactory
    j = JobFactory()
    j.create_job(self, 'create_archive', request.user, your_resource_object_containing_files_to_zip, { 'extra_param': 'value' })

(, ):

./manage.py run_queue

, zip . .

+3

, , Javascript ( Shadowbox, JQuery - ) throbber ( hxxp://www.ajaxload.info/). . , ( ", ..." )

JQUery API . AJAX -, . , , , .

0

" " - .

:

  • , totalfiles.filespreocessed
  • , ,

, 3 , :

3.0 -> begin, no file still processed
3.1 -> 1 file on 3 processed, 33% task complete
3.2 -> 2 file on 3 processed, 66% task complete
3.3 -> 3 file on 3 processed, 100% task complete

ajax () log .

python, , , , , , , , , , , , , rand .

, , ajax , python , .

, , .

0
source

Source: https://habr.com/ru/post/1709280/


All Articles