By Phil Gyford
I’d like to try using App Platform to run some Django sites. Almost every site I’ve made requires one or more commands to be run periodically (e.g. once an hour, once a day, etc). On a VPS I’d use cron to do this, and on Heroku I’d use Heroku Scheduler (with less flexibility).
But I can’t see a way to do this on App Platform. I assume there’s something obvious I’ve missed, as it seems quite a basic feature?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hello, at this time App Platform doesn’t have support to run scheduled tasks (aside from pre/post deployment jobs).
However, if you’re willing to run Django in a container image that your own, you can run cron in tandem with Django to execute whatever management commands that you’d like.
For example:
FROM python:buster
# Install cron (also anything else for Django)
RUN apt-get update \
&& apt-get install -y cron \
&& apt-get update -y
# Assuming you have some scripts that might execute some
# management commands
COPY *.sh /scripts/
RUN chmod +x /scripts/*.sh
WORKDIR /scripts
# Run at the beginning of the hour
RUN echo "0 * * * * root /scripts/management_command.sh" >/etc/cron.d/management_command
# Run both Django and cron together
CMD [ "sh", "-c", "cron && <cmd to run Django>" ]
Hope this helps!
Greg
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.