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

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

问题描述

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

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?

推荐答案

如果您愿意安装 3rd 方库,但又想要比 Celery 简单得多的东西,请查看 Redis Queue.它确实需要 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天全站免登陆