问题
Till now I had only worked with Celery tasks defined as functions. I used to define their periodicity in the CELERYBEAT_SCHEDULE
parameter. Like this:
from datetime import timedelta
CELERYBEAT_SCHEDULE = {
'add-every-30-seconds': {
'task': 'tasks.add',
'schedule': timedelta(seconds=30),
'args': (16, 16)
},
}
Now I am trying to use class-based tasks, like this one:
class MyTask(Task):
"""My Task."""
def run(self, source, *args, **kwargs):
"""Run the celery task."""
logger.info("Hi!")
My question is: how do I define the periodic execution of class-based tasks?
来源:https://stackoverflow.com/questions/37924442/celery-beat-how-to-define-periodic-tasks-defined-as-classes-class-based-tasks