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 ________________________________ From: django-users@googlegroups.com <django-users@googlegroups.com> on behalf of Bartosz Gańcza <gart...@gmail.com> Sent: Friday, November 2, 2018 3:31:38 PM To: django-users@googlegroups.com Subject: Running a custom code after the server is up Hi everyone! I am somewhat of a Django beginner and I can't seem to find an easy solution to what I need to do anywhere. I have a web scraping code I wish to run in the background automatically (once) after the server is up and running. I use Docker to fire up the DB and the web server itself but can't seem to be able to configure it to also fire up the management command I configured that runs the scraping code (I guess using Docker for that is either beyond my current knowledge or is just not possible without using specialised tools like cron, which I don't fully understand). Is there any way to do something like this in Django itself, without resorting to "ready" function? (I did that at first but it stops the server from running until the code completes and also runs it at least twice) Best, Bartosz -- 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+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>. To post to this group, send email to django-users@googlegroups.com<mailto: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<https://groups.google.com/d/msgid/django-users/CAOjbnAWtCMWRck45hgZQqeaY-U86iEmiGs%2Btpq617V81_%2B6hkQ%40mail.gmail.com?utm_medium=email&utm_source=footer>. For more options, visit https://groups.google.com/d/optout. -- 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+unsubscr...@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/VI1P193MB04324F801770E468502CBEC98CCF0%40VI1P193MB0432.EURP193.PROD.OUTLOOK.COM. For more options, visit https://groups.google.com/d/optout.