如何使用 Django 运行自己的守护进程? [英] How to run own daemon processes with Django?

查看:49
本文介绍了如何使用 Django 运行自己的守护进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Django 项目中,我必须在后台反复进行一些处理.这个处理需要访问 Django 的东西,所以我把它放到 Django 的命令中并作为 cronjob 运行它.现在我意识到,我必须更频繁地执行其中的一些操作(cronjob 最多每 1 分钟调用一次命令).另一个问题是我没有足够的控制权来保护一次运行相同的命令.当一个处理时间超过一分钟时就会发生这种情况.我认为我应该像守护进程一样运行它们,但我正在寻找使用 Django 的纯粹方法.您是否遇到过这个问题或知道任何干净的解决方案?

In my Django project I have to do repeatedly some processing in the background. This processing needs access to Django stuff, so I put it into Django's commands and run it as cronjob. Right now I realize, that I have to do some of them more frequently (cronjob has limitation to invoke command at most every 1 minute). Another problem is that I don't have enough control, to protect running the same command in one time. It's happen when one processing takes longer than one minute. I think that I should run them like daemons, but I am looking for pure way to do it with Django. Have you ever faced with this problem or know any clean solution for it?

推荐答案

我们使用 Celery 为 django 做了很多后台处理 http://celeryproject.org/.它需要一些努力来设置并且有一点学习曲线,但是一旦它启动并运行它就很棒.

We do a lot of background processing for django using Celery http://celeryproject.org/. It requires some effort to set up and there is a bit of a learning curve, but once it's up and running it's just awesome.

这篇关于如何使用 Django 运行自己的守护进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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