Created
April 27, 2012 07:34
-
-
Save mjpieters/2506986 to your computer and use it in GitHub Desktop.
plone.app.async decorator template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_decoratedFunctions = {} | |
class _AsyncSomething(object): | |
"""Async job decorator | |
Tracks decorated function via a global mapping instead of storing | |
the function directly to remain pickleable. | |
""" | |
_name = '' | |
def __init__(self, func): | |
self._key = (func.__module__, func.__name__) | |
global _decoratedFunctions | |
_decoratedFunctions[self._key] = func | |
@property | |
def func(self): | |
global _decoratedFunctions | |
return _decoratedFunctions[self._key] | |
def __repr__(self): | |
return '%s.%s' % (self._key) | |
def __call__(self, *args, **kw): | |
# Do pre-call stuff here | |
self.func(context, obj, *args, **kw) | |
# Do post-call stuff here | |
def asyncSomething(func): | |
"""Decorator to enable multi-step batching""" | |
return _AsyncSomething(func) | |
# Example use | |
@asyncSomething | |
def someFunctionForAsyncUse(context, obj): | |
# Blah blah | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment