Ejemplo n.º 1
0
from __future__ import absolute_import, unicode_literals

import os
from celery.app.base import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')

app = Celery('project', backend='redis', broker='redis://localhost:6379')

# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()


@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))
Ejemplo n.º 2
0
import os
from celery.app.base import Celery

# 指django项目的配置文件
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "meiduo_mall.settings.dev")

# 创建一个celery应用(对象), 通常一个项目只需要创建一个celery应用就可以了
# 参数1: 自定义的名字
# 参数2: 异步任务保存到redis中
celery_app = Celery(
    'meiduo',
    broker='redis://127.0.0.1:6379/15',
    # backend: 后台, 保存任务执行的返回值
    backend='redis://127.0.0.1:6379/14')

# celery_app = Celery('meiduo')
# # 加载配置文件
# celery_app.config_from_object('celery_tasks.config')

# 扫描指定的包下面的任务函数
celery_app.autodiscover_tasks(
    ['celery_tasks.sms', 'celery_tasks.email', 'celery_task.html'])
Ejemplo n.º 3
0
from __future__ import absolute_import

import os

from django.conf import settings
from celery.app.base import Celery
import configurations

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings.settings')
os.environ.setdefault('DJANGO_CONFIGURATION', 'Production')
configurations.setup()

app = Celery('app')
app.config_from_object('django.conf:settings')

app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)


@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))