Skip to content

Instantly share code, notes, and snippets.

@theY4Kman
Created December 29, 2014 23:55
Show Gist options
  • Select an option

  • Save theY4Kman/7b9856ad44b06c29fadd to your computer and use it in GitHub Desktop.

Select an option

Save theY4Kman/7b9856ad44b06c29fadd to your computer and use it in GitHub Desktop.
Asynchronous Frontend for Celery Tasks

This library makes it easy to display progress to users on long-running tasks. It can be used directly with existing Celery tasks. Here's a quick demo:

# mymodule/views.py
from celery import task
from hivelocity.asyncweb import async_group

@task
def my_task(a, b, c):
    do_something_longrunning(a, b, c)

def my_view(request):
    group = async_group(1, 2, 3, user=request.user)
    for i in xrange(10):
        group.add_call(i, i*10, i*100)
    return render(request, 'my-template.html', {'task_id': group()})
<!-- my-template.html -->
<h1><span id="progress-text">Nothing</span> done</h1>
<div style="width: 500px; height: 30px; outline: 1px solid black;">
    <div id="progress" style="width: 0; height: 100%; background: blue;"></div>
</div>
<script>
    var task = new AsyncTask('{{ task_id|escapejs }}', {
        'reload_on_complete': true,
        'progress_text': '#progress-text',
        'progress_bar': '#progress'
    });
</script>

This results in a page like this:

Asynchronous Tasks demo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment