在Django中启动后台任务的简单方法 [英] Simple approach to launching background task in Django

查看:115
本文介绍了在Django中启动后台任务的简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Django网站,并且一个页面上有一个按钮(或链接),单击该按钮将启动一个运行时间较长的任务.显然,我想将此任务作为后台任务启动,并立即将结果返回给用户.我想使用一种简单的方法来实现这一点,该方法不需要我安装和学习例如Celery这样的全新消息传递体系结构.我不想用芹菜!我只想使用一种简单的方法,就可以在接下来的半小时左右的时间内进行设置并开始运行.在Django中没有添加(又要添加)第三方软件包的简单方法吗?

I have a Django website, and one page has a button (or link) that when clicked will launch a somewhat long running task. Obviously I want to launch this task as a background task and immediately return a result to the user. I want to implement this using a simple approach that will not require me to install and learn a whole new messaging architecture like Celery for example. I do not want to use Celery! I just want to use a simple approach that I can set up and get running over the next half hour or so. Isn't there a simple way to do this in Django without having to add (yet another) 3rd party package?

推荐答案

如果您愿意安装第3方库,但您想要的东西比Celery简单得多,请查看Redis Queue.它确实需要Redis,Redis本身很容易,但是也可以提供很多其他好处.

If you're willing to install a 3rd party library, but you want something a whole lot simpler than Celery, check out Redis Queue. It does require Redis, which is pretty easy in itself, but that can provide a lot of other benefits as well.

RQ本身几乎具有零配置.非常简单.

RQ itself has almost zero configuration. It's startlingly simple.

参考:

  • http://python-rq.org/
  • http://nvie.com/posts/introducing-rq/
  • https://devcenter.heroku.com/articles/python-rq (RQ on Heroku)

这篇关于在Django中启动后台任务的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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