Hi,
IMHO the simplest way is to use cron.
Since you are working with Docker, one option is to add a container to your stack, sharing the same image as your Django app so that it can run the management command implementing your periodic process. Configure this container so that the command it runs is the cron daemon, and of course schedule your periodic task in the crontab.
Some people use Gunicorn start hook to fork a sub-process running the cron daemon. Others embed supervisor in a container and manage the web app process and the other ones with it. Although it works, such approaches go against the rule which says that a Docker container should handle only one thing (either the app server or the cron stuff in you case) so that it can be managed independantly (scale, update image, restart...).
This is important when you deploy your stack under the control of an orchestrator such as Kubernetes, which will manage the containers (err. the "pods") automatically so that the state or the stack is the targeted one WRT replicas count, resource limits...
Hope this helps.
Eric
Sent: Friday, November 2, 2018 3:31:38 PM
To: django-users@googlegroups.com
Subject: Running a custom code after the server is up
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOjbnAWtCMWRck45hgZQqeaY-U86iEmiGs%2Btpq617V81_%2B6hkQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment