Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 从信号中调用芹菜任务_Django_Celery_Cookiecutter Django - Fatal编程技术网

Django 从信号中调用芹菜任务

Django 从信号中调用芹菜任务,django,celery,cookiecutter-django,Django,Celery,Cookiecutter Django,我需要在用户注册后从几个公共API导入数据。包括django allauth,我注册了一个信号处理程序,在allaut发出用户注册后调用正确的方法。 因为数据导入需要很多时间,而且请求被信号阻塞,所以我想用芹菜来做这项工作 我的测试任务: @app.task() def test_task(username): print('##########################Foo#################') sleep(40) print('########

我需要在用户注册后从几个公共API导入数据。包括django allauth,我注册了一个信号处理程序,在allaut发出
用户注册后调用正确的方法。
因为数据导入需要很多时间,而且请求被信号阻塞,所以我想用芹菜来做这项工作

我的测试任务:

@app.task()
def test_task(username):
    print('##########################Foo#################')
    sleep(40)
    print('##########################' + username + '#################')
    sleep(20)
    print('##########################Bar#################')
    return 3
我这样称呼这个任务:

from game_studies_platform.taskapp.celery import test_task

@receiver(user_signed_up)
def on_user_signed_in(sender, request, *args, **kwargs):
    test_task.apply_async('John Doe')
任务应放入队列中,请求应立即执行。但是它被阻塞了,我不得不等一分钟

项目是用安装的,我正在docker容器中运行它。
芹菜被配置为在开发中使用django数据库,但将在生产中使用redis

解决方案是在local.py中将
芹菜\u ALWAYS\u EAGER=True
切换到
False
。在cookiecutter django的Gitter频道中,我被指向了这个解决方案

上面提到的电话已经正确了