JavaScript module for asynchronously handling Celery task results from the browser.
At least jQuery 1.5. Not tested in jQuery 2.0.
celeryjs
uses a combination of
setTimeout
and
setInterval
with
jQuery.ajax
and
Deferred Object.
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();
});
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.