Celery Beat: How to define periodic tasks defined as classes (class based tasks)

非 Y 不嫁゛ 提交于 2019-12-11 00:50:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!