I was just wondering what the best practice to pass an attribute to base class task would be in Celery 4.3.
I have already working code which looks like:
class BaseTask(app.Task):
abc = None
def __init__(self, *args, **kwargs):
if not self.abc:
raise NotImplementedError('Must implement the abc attribute')
super(BaseTask, self).__init__(*args, **kwargs)
def on_success(self, retval, task_id, args, kwargs):
print(asd) # and do some other work with asd
class MainTask(BaseTask):
abc = 'Here Am I'
def run(self, *args, **kwargs):
print(self.abc) # and do some other great job
MainTask = app.register_task(MainTask())
But as I can see in Celery documentation:
http://docs.celeryproject.org/en/latest/_modules/celery/app/base.html?highlight=register_task
Note:
This is here for compatibility with old Celery 1.0
style task classes, you should not need to use this for
new projects.
The best practice is to use custom task classes only for overriding general behavior, and then using the task decorator to realize the task
it isn't best practice what I have done.
So is there any better way/best practice to pass an attribute to Base Task?