使用djangos manage.py自定义命令启动守护进程服务? [英] Kick off daemonized service using djangos manage.py custom command?

查看:954
本文介绍了使用djangos manage.py自定义命令启动守护进程服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经实现了我的可重用django应用程序中的自定义命令,我想启动一个守护进程的服务,然后返回,我的服务作为一个简单的类与启动方法。当start被调用时,它运行在一个永恒的循环中,休息10秒钟,然后使用django orm来检查项目settings.py文件中配置的数据库,检查给定文件夹中的条目。



我想要能够:

  ./ manage.py startservice 

我的服务和返回。然后在同一个shell中:

  ./ manage.py runserver 

,并开始在特定数据库表中添加条目,该表在5秒钟内由后台运行的服务提取并处理。



我已经看过芹菜更多的基于消息队列的方法,但它依赖于太多其他的东西。重要的是,整个事情遵循django的可重用应用程序模式。



任何提示或想法?

解决方案

我有一个库的开始 django-initd 来处理这个问题:请参阅 GitHub上的项目



Django实际上包含一个用于进程守护进程的实用程序,在 django.utils.daemonize 中,我的库需要关心启动/关闭,记录和与管理命令的交互。我有兴趣知道这对你有帮助。


I got a custom command in my reusable django app which I want to kick off a daemonized service and then return, leaving the service running.

I've implemented my service as a simple class with a start-method. When start is called it runs in an eternal loop, sleeping for 10 seconds, then using the django orm to check the database configured in the projects settings.py file, checks for entries in a given folder.

I want to be able to:

./manage.py startservice

which kicks of my service and returns. Then in the same shell:

./manage.py runserver

and start adding entries in a specific database table which within 5 seconds are picked up by the service running in the background and processed.

I've looked at celery for a more message-queue-based approach, but it relies on too much other stuff. It's important that the whole thing follows django's reusable app pattern.

Any hints or thoughts?

解决方案

I have the beginnings of a library, django-initd, to handle this: see the project on GitHub.

Django actually includes a utility for a process to daemonize itself, in django.utils.daemonize, my library takes care of the startup/shutdown, logging, and interaction with the management command. I'd be interested to know if it's helpful for you.

这篇关于使用djangos manage.py自定义命令启动守护进程服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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