Report this

What is the reason for this report?

How to deploy a background cronjob for my Django application (App Platform)?

Posted on January 20, 2025

I’m looking for an option to run a cronjob in the background that calls a django-admin command. Is there any information about how to approach this using DO’s App Platform?



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!

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.

Heya,

have you considered using Celery and CeleryBeat for that? You can check that discussion here:

https://www.digitalocean.com/community/questions/how-to-set-up-django-app-redis-celery-a06db780-5335-493e-8158-7128ea7d2cc1 While it’s for a Droplet setup you can make a docker file and add Celery.

elery:

Celery is an asynchronous task queue and job scheduler for Python applications. It allows you to run tasks in the background (asynchronously) rather than during the main execution of your application, making it ideal for:

  • Background Processing: Running tasks like sending emails, image processing, or database updates in the background.
  • Distributed Systems: Running tasks across multiple worker nodes.
  • Task Scheduling: Executing tasks at specific times or intervals.

It works by:

  1. Producers: Your app sends tasks to a message broker (e.g., Redis, RabbitMQ).
  2. Consumers: Celery workers fetch and execute those tasks from the message broker.

CeleryBeat:

CeleryBeat is an extension for Celery that adds support for periodic task scheduling. It allows you to define tasks that should run at specific intervals (similar to Cron jobs).

Key features:

  • Stores periodic task schedules in your database.
  • Integrates with Celery to trigger scheduled tasks automatically.
  • Works with PeriodicTask and CrontabSchedule models in Django.

Use cases:

  • Sending daily reports.
  • Running database cleanup tasks.
  • Triggering periodic background operations.

In short:

  • Celery handles background tasks.
  • CeleryBeat schedules periodic tasks for Celery to execute.

That way you can control the tasks/cronjobs from your Django Admin

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.