Browse Source

Rename celery.backends.Job -> celery.task.PendingResult

Ask Solem 16 years ago
parent
commit
26e2af55b1
2 changed files with 40 additions and 37 deletions
  1. 3 36
      celery/backends/__init__.py
  2. 37 1
      celery/task.py

+ 3 - 36
celery/backends/__init__.py

@@ -6,36 +6,6 @@ DEFAULT_BACKEND = "database"
 CELERY_BACKEND = getattr(settings, "CELERY_BACKEND", DEFAULT_BACKEND)
 
 
-class BaseJob(object):
-
-    def __init__(self, task_id, backend):
-        self.task_id = task_id
-        self.backend = backend
-
-    def __str__(self):
-        return self.task_id
-
-    def __repr__(self):
-        return "<Job: %s>" % self.task_id
-
-    def is_done(self):
-        return self.backend.is_done(self.task_id)
-
-    def wait_for(self):
-        return self.backend.wait_for(self.task_id)
-
-    @property
-    def result(self):
-        if self.status == "DONE":
-            return self.backend.get_result(self.task_id)
-        return None
-
-    @property
-    def status(self):
-        return self.backend.get_status(self.task_id)
-
-
-
 def get_backend_cls(backend):
     if backend.find(".") == -1:
         backend = "celery.backends.%s" % backend
@@ -44,12 +14,9 @@ def get_backend_cls(backend):
     return getattr(backend_module, 'Backend')
 
 get_default_backend_cls = partial(get_backend_cls, CELERY_BACKEND)
-DefaultBackend = get_default_backend_cls()
-default_backend = DefaultBackend()
 
-class Job(BaseJob):
-    
-    def __init__(self, task_id):
-        super(Job, self).__init__(task_id, backend=default_backend)
+
+DefaultBackend = get_default_backend_cls()
 
 
+default_backend = DefaultBackend()

+ 37 - 1
celery/task.py

@@ -6,11 +6,47 @@ from celery.messaging import TaskPublisher, TaskConsumer
 from celery.models import TaskMeta
 from django.core.cache import cache
 from datetime import timedelta
-from celery.backends import Job, default_backend
+from celery.backends import default_backend
 import uuid
 import traceback
 
 
+class BasePendingResult(object):
+    """Base class for pending result, takes ``backend`` argument."""
+    def __init__(self, task_id, backend):
+        self.task_id = task_id
+        self.backend = backend
+
+    def __str__(self):
+        return self.task_id
+
+    def __repr__(self):
+        return "<Job: %s>" % self.task_id
+
+    def is_done(self):
+        return self.backend.is_done(self.task_id)
+
+    def wait_for(self):
+        return self.backend.wait_for(self.task_id)
+
+    @property
+    def result(self):
+        if self.status == "DONE":
+            return self.backend.get_result(self.task_id)
+        return None
+
+    @property
+    def status(self):
+        return self.backend.get_status(self.task_id)
+
+
+class PendingResult(BasePendingResult):
+    """Pending task result using the default backend.""" 
+
+    def __init__(self, task_id):
+        super(PendingResult, self).__init__(task_id, backend=default_backend)
+
+
 def delay_task(task_name, *args, **kwargs):
     """Delay a task for execution by the ``celery`` daemon.