Browse Source

Can now check if a task has been executed or not via HTTP.

You can do this by including the celery urls.py into your project:

    url(r'^celery/$', include("celery.urls"))

then visiting the following url:

    http://mysite/celery/$task_id/done/

this will return a JSON dictionary like e.g:

    {"task": {"id": $task_id, "executed": true}}
Ask Solem 16 years ago
parent
commit
d47c3a987b
2 changed files with 19 additions and 0 deletions
  1. 2 0
      celery/process.py
  2. 17 0
      celery/task.py

+ 2 - 0
celery/process.py

@@ -1,4 +1,5 @@
 from UserList import UserList
+from celery.task import mark_as_done
 
 
 class ProcessQueue(UserList):
@@ -22,4 +23,5 @@ class ProcessQueue(UserList):
                         "name": task_name,
                         "id": task_id,
                         "return_value": ret_value})
+                    mark_as_done(task_id)
             self.data = []

+ 17 - 0
celery/task.py

@@ -2,6 +2,7 @@ from carrot.connection import DjangoAMQPConnection
 from celery.log import setup_logger
 from celery.registry import tasks
 from celery.messaging import TaskPublisher, TaskConsumer
+from django.core.cache import cache
 
 
 def delay_task(task_name, **kwargs):
@@ -22,6 +23,22 @@ def discard_all():
     return discarded_count
 
 
+def gen_task_done_cache_key(task_id):
+    return "celery-task-done-marker-%s" % task_id
+
+
+def mark_as_done(task_id, result):
+    if result is None:
+        result = True
+    cache_key = gen_task_done_cache_key(task_id)
+    cache.set(cache_key, result)
+
+
+def is_done(task_id):
+    cache_key = gen_task_done_cache_key(task_id)
+    return cache.get(cache_key)
+
+
 class Task(object):
     name = None
     type = "regular"