Kick off daemonized service using djangos manage.py custom command?
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-开发者_StackOverflowqueue-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.
Why do you want to start service as a separte process?
Run in a Thread, in the same process as runserver.
精彩评论