【发布时间】:2021-01-15 11:59:45
【问题描述】:
我需要我的 django 视图函数来触发一个任务,该任务将在后台运行,而不是阻塞响应。
def my_task(client_information, unique_id): # task
#do something that takes a while
def my_view(request): # django view
client_information = request.GET.get('whatever') # get some information passed from the client
unique_id = generate_unique_id() # generate a unique ID for this task
start_task(client_information, unique_id) # the interesting part: start the task with client information and unique id, but non blocking
return JsonResponse({'id': unique_id})
我阅读了有关 celery 的文章,但我看到的代码看起来有点过头了,因为我不需要进程之间的任何进一步通信,我真的想要一个尽可能轻量级的解决方案。
【问题讨论】:
标签: python django asynchronous queue celery