Ask Solem il y a 12 ans
Parent
commit
0858f6e0ee
2 fichiers modifiés avec 22 ajouts et 37 suppressions
  1. 14 26
      celery/app/task.py
  2. 8 11
      celery/datastructures.py

+ 14 - 26
celery/app/task.py

@@ -28,10 +28,9 @@ from .registry import _unpickle_task_v2
 
 #: extracts attributes related to publishing a message from an object.
 extract_exec_options = mattrgetter(
-    'queue', 'routing_key', 'exchange',
-    'immediate', 'mandatory', 'priority', 'expires',
-    'serializer', 'delivery_mode', 'compression',
-    'timeout', 'soft_timeout',
+    'queue', 'routing_key', 'exchange', 'priority', 'expires',
+    'serializer', 'delivery_mode', 'compression', 'timeout', 'soft_timeout',
+    'immediate', 'mandatory',  # imm+man is deprecated
 )
 
 
@@ -60,19 +59,10 @@ class Context(object):
     _protected = 0
 
     def __init__(self, *args, **kwargs):
-        self.update(*args, **kwargs)
-
-    def update(self, *args, **kwargs):
-        self.__dict__.update(*args, **kwargs)
-
-    def clear(self):
-        self.__dict__.clear()
-
-    def get(self, key, default=None):
-        try:
-            return getattr(self, key)
-        except AttributeError:
-            return default
+        self.get = self.__dict__.get
+        self.clear = self.__dict__.clear
+        update = self.update = self.__dict__.update
+        update(*args, **kwargs)
 
     def __repr__(self):
         return '<Context: {0!r}>'.format(vars(self))
@@ -88,11 +78,11 @@ class Context(object):
 class TaskType(type):
     """Meta class for tasks.
 
-    Automatically registers the task in the task registry, except
-    if the `abstract` attribute is set.
+    Automatically registers the task in the task registry (except
+    if the :attr:`Task.abstract`` attribute is set).
 
-    If no `name` attribute is provided, then no name is automatically
-    set to the name of the module it was defined in, and the class name.
+    If no :attr:`Task.name` attribute is provided, then the name is generated
+    from the module and class name.
 
     """
 
@@ -378,14 +368,12 @@ class Task(object):
 
         :keyword countdown: Number of seconds into the future that the
                             task should execute. Defaults to immediate
-                            execution (do not confuse with the
-                            `immediate` flag, as they are unrelated).
+                            execution.
 
         :keyword eta: A :class:`~datetime.datetime` object describing
                       the absolute time and date of when the task should
                       be executed.  May not be specified if `countdown`
-                      is also supplied.  (Do not confuse this with the
-                      `immediate` flag, as they are unrelated).
+                      is also supplied.
 
         :keyword expires: Either a :class:`int`, describing the number of
                           seconds, or a :class:`~datetime.datetime` object
@@ -553,7 +541,7 @@ class Task(object):
             ...         raise tweet.retry(countdown=60 * 5, exc=exc)
 
         Although the task will never return above as `retry` raises an
-        exception to notify the worker, we use `return` in front of the retry
+        exception to notify the worker, we use `raise` in front of the retry
         to convey that the rest of the block will not be executed.
 
         """

+ 8 - 11
celery/datastructures.py

@@ -11,7 +11,7 @@ from __future__ import absolute_import, print_function, unicode_literals
 import sys
 import time
 
-from collections import defaultdict, Mapping, MutableMapping
+from collections import defaultdict, Mapping, MutableMapping, MutableSet
 from heapq import heapify, heappush, heappop
 from functools import partial
 from itertools import chain
@@ -188,7 +188,7 @@ class DependencyGraph(object):
         return [t[0] for t in graph._khan62()]
 
     def valency_of(self, obj):
-        """Returns the velency (degree) of a vertex in the graph."""
+        """Returns the valency (degree) of a vertex in the graph."""
         try:
             l = [len(self[obj])]
         except KeyError:
@@ -354,6 +354,7 @@ class DictAttribute(object):
     """Dict interface to attributes.
 
     `obj[k] -> obj.k`
+    `obj[k] = val -> obj.k = val`
 
     """
     obj = None
@@ -414,6 +415,7 @@ class DictAttribute(object):
 
         def items(self):
             return list(self._iterate_items())
+MutableMapping.register(DictAttribute)
 
 
 class ConfigurationView(AttributeDictMixin):
@@ -512,7 +514,6 @@ class ConfigurationView(AttributeDictMixin):
 
     def values(self):
         return list(self._iterate_values())
-
 MutableMapping.register(ConfigurationView)
 
 
@@ -520,8 +521,7 @@ class LimitedSet(object):
     """Kind-of Set with limitations.
 
     Good for when you need to test for membership (`a in set`),
-    but the list might become to big, so you want to limit it so it doesn't
-    consume too much resources.
+    but the list might become to big.
 
     :keyword maxlen: Maximum number of members before we start
                      evicting expired members.
@@ -536,6 +536,8 @@ class LimitedSet(object):
         self._data = {} if data is None else data
         self._heap = [] if heap is None else heap
         self.__len__ = self._data.__len__
+        self.__contains__ = self._data.__contains__
+        self.__iter__ = self._data.__iter__
 
     def add(self, value):
         """Add a new member."""
@@ -570,9 +572,6 @@ class LimitedSet(object):
         """Hunt down and remove an expired item."""
         self.purge(1)
 
-    def __contains__(self, value):
-        return value in self._data
-
     def purge(self, limit=None):
         H, maxlen = self._heap, self.maxlen
         if not maxlen:
@@ -604,9 +603,6 @@ class LimitedSet(object):
     def as_dict(self):
         return self._data
 
-    def __iter__(self):
-        return iter(self._data)
-
     def __repr__(self):
         return 'LimitedSet(%s)' % (repr(list(self._data))[:100], )
 
@@ -618,3 +614,4 @@ class LimitedSet(object):
     def first(self):
         """Get the oldest member."""
         return self._heap[0][1]
+MutableSet.register(LimitedSet)