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