Google App Engine 上 Django 的后台任务

问题描述

我有一个问题,我找不到(简单的)解决方案。

目前在views.py

from .utils import some_heavy_function

@login_required
def my_function_view(request):
    user = request.user
    instance = MyModel(user=user)
    
    if request.method == "POST":
        form = MyModel_form(request.POST,instance = instance)    

        if form.is_valid():

            form.save(commit=False)
            
            #Run function which saves the form
            some_heavy_function(form)


            messages.success(request,"Success!")
            return redirect("my_template")
    else:
        form = MyModel_form()

    return render(request,"my_app/my_html.html")

如您所见,当用户提交表单时,我想在后台运行 some_heavy_function - 它所做的只是运行 python 脚本并根据脚本。用户不应等待这结束。

我已经研究了 form.instancedjango-background-tasksdjango-q,但我还没有设法使它起作用(sync_to_async 不适用于 sync_to_async@login_required 在 Windows 上不起作用,redis 需要额外调用才能实际执行排队的进程)

这样做的最佳方法是什么?我的 Django 应用程序在 Google App Engine 上运行,如果这样更容易

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)