Created
July 2, 2012 02:33
-
-
Save binarymatt/3030583 to your computer and use it in GitHub Desktop.
pyres decorator
This file contains 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
from pyres import ResQ | |
def job(queue, resq=ResQ(),debug=False): | |
def wrapper(func): | |
def enqueue(*args): | |
if not debug: | |
class_name = '%s.%s' % (func.__module__, func.__name__) | |
resq.enqueue_from_string(class_name, queue, *args) | |
else: | |
return func(*args) | |
def __call__(self, *args): | |
return func(*args) | |
new_class = type('Job',(),{ | |
'queue': queue, | |
'perform': staticmethod(func), | |
'enqueue': staticmethod(enqueue), | |
'__call__': __call__, | |
'__name__': func.__name__ | |
}) | |
return new_class() | |
return wrapper | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment