我在ubuntu EC2节点上有一个django项目,它执行一个计算密集的长时间运行过程,通常需要60秒以上。我需要缓存结果。{a1和}我一直在看^和^文档。我已经能够在命令行中运行一个基本任务,但是我不清楚如何从django函数内部启动任务。在
现在我的django视图中代码的结构是:
from django.shortcuts import render
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from __future__ import absolute_import
from celery import shared_task
@csrf_exempt
def index(request):
token = str(request.POST.get('token', False))
calculator(token)
return HttpResponse(token)
@shared_task
def calculator(token):
# do calculation
# store result in cache
return
是不是很简单:
^{pr2}$在索引函数中?在
就像你说的一样简单:
或者
^{pr2}$有关如何调用任务的详细信息,请参见the docs。在
相关问题 更多 >
编程相关推荐