How to regularly run Django management commands on App Platform

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?

Submit an answer

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!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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/" >/etc/cron.d/management_command

# Run both Django and cron together
CMD [ "sh", "-c", "cron && <cmd to run Django>" ]

Hope this helps!