Skip to main content

Drop in, configurable, dependency-free progress bars for your Django/Celery applications.

Project description

Drop in, dependency-free progress bars for your Django/Celery applications.

Super simple setup. Lots of customization available.

Demo

Celery Progress Bar demo on Build With Django

Installation

pip install celery-progress

Usage

Prerequisites

First add celery_progress to your INSTALLED_APPS in settings.py.

Then add the following url config to your main urls.py:

url(r'^celery-progress/', include('celery_progress.urls')),  # the endpoint is configurable

Recording Progress

In your task you should add something like this:

from celery import shared_task
from celery_progress.backend import ProgressRecorder
import time

@shared_task(bind=True)
def my_task(self, seconds):
    progress_recorder = ProgressRecorder(self)
    for i in range(seconds):
        time.sleep(1)
        progress_recorder.set_progress(i + 1, seconds)
    return 'done'

Displaying progress

In the view where you call the task you need to get the task ID like so:

views.py

def progress_view(request):
    result = my_task.delay(10)
    return render(request, 'display_progress.html', context={'task_id': result.task_id})

Then in the page you want to show the progress bar you just do the following.

Add the following HTML wherever you want your progress bar to appear:

display_progress.html

<div class='progress-wrapper'>
  <div id='progress-bar' class='progress-bar' style="background-color: #68a9ef; width: 0%;">&nbsp;</div>
</div>
<div id="progress-bar-message">Waiting for progress to start...</div>

Import the javascript file.

display_progress.html

<script src="{% static 'celery_progress/celery_progress.js' %}"></script>

Initialize the progress bar:

// vanilla JS version
document.addEventListener("DOMContentLoaded", function () {
  var progressUrl = "{% url 'celery_progress:task_status' task_id %}";
  CeleryProgressBar.initProgressBar(progressUrl);
});

or

// JQuery
$(function () {
  var progressUrl = "{% url 'celery_progress:task_status' task_id %}";
  CeleryProgressBar.initProgressBar(progressUrl)
});

Customization

The initProgressBar function takes an optional object of options. The following options are supported:

Option

What it does

Default Value

pollInter val

How frequently to poll for progress (in milliseconds)

500

progressB arId

Override the ID used for the progress bar

‘progress-bar’

progressB arMessage Id

Override the ID used for the progress bar message

‘progress-bar-me ssage’

progressB arElement

Override the element used for the progress bar. If specified, progressBarId will be ignored.

document.getElem entById(progress BarId)

progressB arMessage Element

Override the element used for the progress bar message. If specified, progressBarMess ageId will be ignored.

document.getElem entById(progress BarMessageId)

onProgres s

function to call when progress is updated

CeleryProgressBa r.onProgressDefa ult

onSuccess

function to call when progress successfully completes

CeleryProgressBa r.onSuccessDefau lt

onError

function to call when progress completes with an error

CeleryProgressBa r.onErrorDefault

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

celery-progress-0.0.4.tar.gz (5.6 kB view details)

Uploaded Source

File details

Details for the file celery-progress-0.0.4.tar.gz.

File metadata

  • Download URL: celery-progress-0.0.4.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.5

File hashes

Hashes for celery-progress-0.0.4.tar.gz
Algorithm Hash digest
SHA256 de859f0ebec6a29edd0261d986539d726e02fc244ff6e1894615351c2ec50f78
MD5 c2e2d787d659e5444917a776e1b6696c
BLAKE2b-256 1781e8938a6845cb3aa6952cd34cfc7d4db22a58086666f511323a1d8d2b7b7b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page