소스 검색

Cosmetics

Ask Solem 11 년 전
부모
커밋
0624888cfb
2개의 변경된 파일19개의 추가작업 그리고 17개의 파일을 삭제
  1. 16 17
      celery/app/base.py
  2. 3 0
      celery/app/task.py

+ 16 - 17
celery/app/base.py

@@ -265,26 +265,25 @@ class Celery(object):
                     sum([len(args), len(opts)])))
         return inner_create_task_cls(**opts)
 
-    def _task_from_fun(self, fun, name=None, **options):
+    def _task_from_fun(self, fun, name=None, base=None, bind=False, **options):
         if not self.finalized and not self.autofinalize:
             raise RuntimeError('Contract breach: app not finalized')
-        base = options.pop('base', None) or self.Task
-        bind = options.pop('bind', False)
-
         name = name or gen_task_name(self, fun.__name__, fun.__module__)
-
-        T = type(fun.__name__, (base, ), dict({
-            'app': self,
-            'name': name,
-            'run': fun if bind else staticmethod(fun),
-            '_decorated': True,
-            '__doc__': fun.__doc__,
-            '__module__': fun.__module__,
-            '__wrapped__': fun}, **options))()
-        if T.name not in self._tasks:
-            self._tasks.register(T)
-            T.bind(self)  # connects task to this app
-        task = self._tasks[T.name]  # return global instance.
+        base = base or self.Task
+
+        if name not in self._tasks:
+            task = type(fun.__name__, (base, ), dict({
+                'app': self,
+                'name': name,
+                'run': fun if bind else staticmethod(fun),
+                '_decorated': True,
+                '__doc__': fun.__doc__,
+                '__module__': fun.__module__,
+                '__wrapped__': fun}, **options))()
+            self._tasks[task.name] = task
+            task.bind(self)  # connects task to this app
+        else:
+            task = self._tasks[name]
         return task
 
     def finalize(self, auto=False):

+ 3 - 0
celery/app/task.py

@@ -43,6 +43,9 @@ R_UNBOUND_TASK = '<unbound {0.__name__}{flags}>'
 R_SELF_TASK = '<@task {0.name} bound to other {0.__self__}>'
 R_INSTANCE = '<@task: {0.name} of {app}{flags}>'
 
+#: Here for backwards compatibility as tasks no longer use a custom metaclass.
+TaskType = type
+
 
 def _strflags(flags, default=''):
     if flags: