celery.contrib.methods: Task decorator for methods
To use::
from celery.contrib.methods import task
class X(object):
@task
def add(self, x, y):
return x + y
or with any task decorator:
from celery.contrib.methods import task_method
class X(object):
@celery.task(filter=task_method)
def add(self, x, y):
return x + y
Caveats:
- Autmatic naming won't be able to know what the class name is.
The name will still be module_name + task_name,
so two methods with the same name in the same module will collide
so that only one task can run::
class A(object):
@task
def add(self, x, y):
return x + y
class B(object):
@task
def add(self, x, y):
return x + y
would have to be written as:
class A(object):
@task(name="A.add")
def add(self, x, y):
return x + y
class B(object):
@task(name="B.add")
def add(self, x, y):
return x + y