我如何知道Django代码中芹菜后台处理是否成功.如果成功,我要呈现一个html页面 [英] How will I know if celery background process is successful inside django code. If it is successful I want render a html page

查看:54
本文介绍了我如何知道Django代码中芹菜后台处理是否成功.如果成功,我要呈现一个html页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法执行此操作,因为Django代码中没有当前正在运行的后台进程的状态.

I am not able to do because I don't have the status of the currently running background process in the django code.

请求:我需要知道celery后台任务的状态并从那里渲染html页面

Request: I need to know the status of the celery background task and render the html page from there

@task_success.connect
def task_sent_handler3(sender=None,result=None,**kwargs):
    # information about task are located in headers for task messages
    # using the task protocol version 2.
    #info = headers if 'task' in headers else body
    tester()
    #print('after_task_publish for task id {info[id]}'.format(info="hhhi",))

我尝试了上述芹菜注解,但未返回任何内容.如果返回,我也可以访问局部变量并返回渲染函数

I tried the above celery annotation but i did not return anything. If it return also will i be able to access the local variables and return the render function

从该成功修饰函数中渲染(request,'page.html')

render(request,'page.html') from that success decoration function

我该如何解决?

推荐答案

当您为每个任务运行任务时,都会有唯一的ID.通过该ID,您可以跟踪任务的状态.在正面,您可以仅检查发送该ID的ajax调用的状态.完成后,您可以显示想要显示的内容.

when you run the task for every task there will be unique id for that. from that id you can track the status of the task. on front side you can just check the status of sending the ajax call for that id. when it gets complete you can display the whatever you want to display.

http://thoslin.github.io/async-download-with-芹菜/

这篇关于我如何知道Django代码中芹菜后台处理是否成功.如果成功,我要呈现一个html页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆