Мне просто интересно, как лучше всего передать атрибут для задачи базового класса в Celery 4.3.
У меня уже есть рабочий код, который выглядит следующим образом:
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())
Нокак я вижу в документации Celery:
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.
и http://docs.celeryproject.org/en/4.0/whatsnew-4.0.html#the-task-base-class-no-longer-automatically-register-tasks
The best practice is to use custom task classes only for overriding general behavior, and then using the task decorator to realize the task
это не лучшая практика, что я сделал,
Так есть ли лучший способ / лучший способ передать атрибут в базовую задачу?