Skip to content

Instantly share code, notes, and snippets.

@MaikuMori
Created June 11, 2014 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaikuMori/268b957243d589018bc0 to your computer and use it in GitHub Desktop.
Save MaikuMori/268b957243d589018bc0 to your computer and use it in GitHub Desktop.
CeleryTaskProxy
class CeleryTaskProxy(object):
"""
Method proxy to execute namespaced Celery tasks via send_task.
"""
def __init__(self, celery, namespace):
self._celery = celery
self._namespace = namespace
def __getattr__(self, attr):
def runner(*args, **kwargs):
task_name = "{}.{}".format(self._namespace, attr)
return self._celery.send_task(task_name, args, kwargs)
return runner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment