Skip to content

JavaScript module for asynchronously handling Celery task results from the browser

License

Notifications You must be signed in to change notification settings

PolicyStat/celeryjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

celeryjs

JavaScript module for asynchronously handling Celery task results from the browser.

Requirements

At least jQuery 1.5. Not tested in jQuery 2.0.

How it works

celeryjs uses a combination of setTimeout and setInterval with jQuery.ajax and Deferred Object.

Usage

celeryjs exposes a single function CeleryJS that returns a Deferred Object.

var celery = CeleryJS({
    url: '/task/.../status',
    checkInterval: 3000,  // (default) milliseconds
    ajax: {               // (default) options passed to jQuery.ajax
        cache: false,
        dataType: 'json',
    }
});
// Called when task.status is not SUCCESS or FAILURE (e.g. PENDING)
celery.progress(function(task) {
    updateTaskStatus(task.status);
});
// Called when task.status is FAILURE or the ajax request fails
celery.fail(function(task) {
    displayError(task);
});
// Called when task.status is SUCCESS
celery.done(function(task) {
    displayResult(task.result);
});
// Always called
celery.always(function(task) {
    hideLoadingSpinner();
});

Celery task status format

celeryjs expects the URL that you pass to it to return a JSON object that has the format below.

{
    task: {
        status: "SUCCESS"|"FAILURE"|"..."
    }
}

task.status corresponds to AsyncResult.state.

Additional keys and values may be present.

The above JSON object is a subset of the format used by django-celery's celery-task_status URL.

About

JavaScript module for asynchronously handling Celery task results from the browser

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published