環境
unix
Python2.7
Django1.8
Celery3.1
django-celery3.1
需要安装
pip install celery
pip install django-celery
代码
代码的框架
djangotest
└-apptest
└-tasks.py
└-
└-djangotest
└-celery.py
└-settings.py
代码
__init__.py
from __future__ import absolute_import
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app # noqa
djangotest/setting.py
# 30秒进行一次处理
from datetime import timedelta
CELERYBEAT_SCHEDULE = {
'add-every-30-seconds': {
'task': 'apptest.tasks.test_celery',
'schedule': timedelta(seconds=30),
'args': (16, 16)
},
# Executes every Monday morning at 7:30 A.M
'add-every-1-minute': {
'task': 'apptest.tasks.test_celery3',
'schedule': crontab(minute='*/1'),
'args': ('test_celery3',),
},
}
CELERY_TIMEZONE = 'UTC