Running maintenance on a Django web app on the app service with manage.py

Matthew Bellringer 26 Reputation points
2022-01-22T17:25:45.677+00:00

I'm stuck on how to implement a Django based web app on the Azure App Service. I can get the thing up and running. The problem is, I'm using Wagtail, which like many Django-based apps relies on regular management function runs. There's a script, manage.py, in the root of the app which you run in order to do this.

Whilst I can do this with SSH for one-off tasks, some of the functions need to run every hour or so, and other triggered by certain events. So, I need to find a way to automate these. If this was a full OS instance it would be a simple as a cron job and whatever orchestration framework I wanted to use, but obviously those options aren't available to me in App Engine.

Have you found a way to run Django management functions in your app on a schedule, or on a trigger of some sort? Without them, App Engine is functionally useless for my project. I can't believe many people would be running Django apps on the platform without being able to do this somehow! Or is everyone running Django apps in containers instead?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,908 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Andriy Bilous 10,976 Reputation points MVP
    2022-01-24T12:28:48.693+00:00

    Hello @Matthew Bellringer

    You can run background tasks with WebJobs in Azure App Service Windows.
    WebJobs is a feature of Azure App Service that enables you to run a program or script in the same instance as a web app, API app, or mobile app. There is no additional cost to use WebJobs.

    You can use the Azure WebJobs SDK with WebJobs to simplify many programming tasks. WebJobs is not yet supported for App Service on Linux.

    There are several WebJob types:

    • Continuous - Starts immediately when the WebJob is created. To keep the job from ending, the program or script typically does its work inside an endless loop. If the job does end, you can restart it. Typically used with WebJobs SDK.
    • Triggered - Starts only when triggered manually or on a schedule.

    The following file types are supported:

    If you are going to run background tasks using Django Python in Linux or Docker I would recommend Azure Function instead
    https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=azurecli-linux%2Capplication-level