사용 환경 : Ubuntu 14.04 / python 3.5 / PyCharm 5.0.3 / Celery 3.1


Periodic Tasks

http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html



스케쥴러 celery beat를 이용하여 주기적으로 반복적인 일을 처리한다.


celeryconfig.py
from datetime import timedelta

CELERYBEAT_SCHEDULE = {
    'add-every-30-seconds': {
        'task': 'tasks.add',
        'schedule': timedelta(seconds=30),
        'args': (16, 16)
    },
}

CELERY_TIMEZONE = 'UTC'


비트 실행

>> celery -A proj beat


워커와 같이 실행

>> celery -A proj worker -B



시간으로 crontab 사용 가능.

from celery.schedules import crontab

CELERYBEAT_SCHEDULE = {
    # Executes every Monday morning at 7:30 A.M
    'add-every-monday-morning': {
        'task': 'tasks.add',
        'schedule': crontab(hour=7, minute=30, day_of_week=1),
        'args': (16, 16),
    },
}