From 060e4a666fb2936bfac238bdb7e27777fa2e4ba9 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 22 Dec 2010 15:09:34 +0530 Subject: [PATCH] add django.views.taks_status --- ox/django/views.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 ox/django/views.py diff --git a/ox/django/views.py b/ox/django/views.py new file mode 100644 index 0000000..3d856c7 --- /dev/null +++ b/ox/django/views.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# vi:si:et:sw=4:sts=4:ts=4 +from celery.utils import get_full_cls_name +from celery.backends import default_backend + +from shortcuts import json_response + + +def task_status(request, task_id): + response = json_response(status=200, text='ok') + status = default_backend.get_status(task_id) + res = default_backend.get_result(task_id) + response['data'] = { + 'id': task_id, + 'status': status, + 'result': res + } + if status in default_backend.EXCEPTION_STATES: + traceback = default_backend.get_traceback(task_id) + response['data'].update({'result': str(res.args[0]), + 'exc': get_full_cls_name(res.__class__), + 'traceback': traceback}) + response['status'] = 500 + return response +