Python django函数内部的基本芹菜任务函数调用
我在ubuntu EC2节点上有一个django项目,它执行一个计算密集的长时间运行过程,通常需要60秒以上。我需要缓存结果。我一直在阅读和阅读文档。我已经能够在命令行中完成一项基本任务,但我不清楚如何从django函数内部启动任务 现在,我在django视图中的代码结构是:Python django函数内部的基本芹菜任务函数调用,python,django,celery,Python,Django,Celery,我在ubuntu EC2节点上有一个django项目,它执行一个计算密集的长时间运行过程,通常需要60秒以上。我需要缓存结果。我一直在阅读和阅读文档。我已经能够在命令行中完成一项基本任务,但我不清楚如何从django函数内部启动任务 现在,我在django视图中的代码结构是: from django.shortcuts import render from django.http import HttpResponse from django.views.decorators.csrf impo
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
它是否像呼叫一样简单:
calculator(token)
在索引函数中?几乎和您所说的一样简单:
calculator.apply_async()
或
有关更多详细信息,请参阅如何调用任务。谢谢,这很有帮助!!
calculator.delay()