标签:work code ams 注意 mes rate future user sha
...
LANGUAGE_CODE = ‘zh-hans‘
TIME_ZONE = ‘Asia/Shanghai‘
USE_I18N = True
USE_L10N = True
USE_TZ = False
CELERY_BROKER_URL = ‘amqp://guest:guest@localhost:5672‘
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
# 设置环境变量
os.environ.setdefault(‘DJANGO_SETTINGS_MODULE‘, ‘project_name.settings‘)
# 注册Celery的APP
app = Celery(‘project_name‘)
# 绑定配置文件
app.config_from_object(‘django.conf:settings‘, namespace=‘CELERY‘)
# 自动发现各个app下的tasks.py文件
app.autodiscover_tasks()
from __future__ import absolute_import, unicode_literals
from .celery import app as celery_app
__all__ = [‘celery_app‘]
# -*- coding: utf-8 -*-
from celery.task import task
# 自定义要执行的task任务
@task
def print_hello():
return ‘hello celery and django...‘
from celery.schedules import crontab
CELERY_BEAT_SCHEDULE = {
# 周期性任务
‘task-one‘: {
‘task‘: ‘app.tasks.print_hello‘,
‘schedule‘: 5.0, # 每5秒执行一次
# ‘args‘: ()
},
# 定时任务
‘task-two‘: {
‘task‘: ‘app.tasks.print_hello‘,
‘schedule‘: crontab(minute=0, hour=‘*/3,10-19‘),
# ‘args‘: ()
}
}
celery -A project_name worker -l info -P eventlet
celery -A project_name beat -l info
celery multi start w1 -A fushentang -l info -P eventlet
pip install django-celery-results
INSTALLED_APPS = (
...,
‘django_celery_results‘,
)
python manage.py migrate django_celery_results
CELERY_RESULT_BACKEND = ‘django-db‘
(用数据库存放任务执行结果信息)【Python】Django2.0集成Celery4.1详解
标签:work code ams 注意 mes rate future user sha
原文地址:https://www.cnblogs.com/thinheader/p/9455705.html