Skip to content

Commit

Permalink
subtask.id is now an alias to subtask['options']['task_id']
Browse files Browse the repository at this point in the history
  • Loading branch information
ask committed Jan 31, 2013
1 parent 470be26 commit e99d977
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions celery/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,53 @@


class _getitem_property(object):
"""Attribute -> dict key descriptor.
def __init__(self, key):
self.key = key
The target object must support ``__getitem__``,
and optionally ``__setitem__``.
Example:
class Me(dict):
deep = defaultdict(dict)
foo = _getitem_property('foo')
deep_thing = _getitem_property('deep.thing')
>>> me = Me()
>>> me.foo
None
>>> me.foo = 10
>>> me.foo
10
>>> me['foo']
10
>>> me.deep_thing = 42
>>> me.deep_thinge
42
>>> me.deep:
defaultdict(<type 'dict'>, {'thing': 42})
"""

def __init__(self, keypath):
path, _, self.key = keypath.rpartition('.')
self.path = path.split('.') if path else None

def _path(self, obj):
return (reduce(lambda d, k: d[k], [obj] + self.path) if self.path
else obj)

def __get__(self, obj, type=None):
if obj is None:
return type
return obj.get(self.key)
return self._path(obj).get(self.key)

def __set__(self, obj, value):
obj[self.key] = value
self._path(obj)[self.key] = value


class Signature(dict):
Expand Down Expand Up @@ -222,6 +258,7 @@ def _apply_async(self):
return self.type.apply_async
except KeyError:
return _partial(current_app.send_task, self['task'])
id = _getitem_property('options.task_id')
task = _getitem_property('task')
args = _getitem_property('args')
kwargs = _getitem_property('kwargs')
Expand Down

0 comments on commit e99d977

Please sign in to comment.