🩺 System status
The system status page shows whether the things your site depends on work: the database, the cache, the media storage, the task queue and outgoing email. Below that it lists the tasks that are waiting, running or finished, and the tasks that run on a schedule, and it runs maintenance commands such as making the media library's image sizes. Your own apps add their services, tasks and commands to it.


Setup
Add the app to INSTALLED_APPS and run migrate: its one table keeps the
latest run of each maintenance command.
# settings.py
INSTALLED_APPS = [
# ...
"content_studio",
"content_studio.contrib.status",
]
Superusers then find System status in the user menu, the menu under their name.
What the page shows
- Services, grouped by app, each with a status: Operational, Degraded, Down or Not checked. A degraded or down service says what is wrong.
- Recent tasks: the tasks that are queued or running, then the latest finished ones, with their duration and the error of a failed task.
- Recurring tasks: the tasks that run on a schedule, with their latest run and their next. A task that is past its time shows as due.
- Maintenance: commands you run with a button, each with its latest run. See Maintenance commands.
- Recent errors: with error reports by email and the notifications app, the viewer's latest error notifications and how often each happened.
The services are checked when someone opens the page or presses Refresh.
The results are remembered for a minute
(STATUS_CACHE_TIMEOUT), so opening
the page again does not run every check again. The task lists refresh every
10 seconds while the page is open.
While a service is degraded or down, a dot shows on the avatar at the bottom of the main menu and on the menu item. For this the admin asks for the overall status every five minutes; within a minute of the last check that runs no checks.
Nothing is checked in the background, and no history is kept: the page shows how things are now. For alerts when nobody is looking, use a monitoring service.
Built-in checks
| Service | What is checked | Not checked when |
|---|---|---|
| Database | Every database in DATABASES answers SELECT 1. An answer that takes more than a second is degraded. | |
| Cache | A value can be stored in the default cache and read back. | The cache is Django's dummy cache. |
| Media storage | The default file storage answers. More than two seconds is degraded. | |
| Task queue | What the task adapter reports, see Tasks. | No task backend is connected, or its adapter has no get_health(). |
| Worker | The worker heartbeat is less than three minutes old; the row shows when the worker last beat. | Tasks run in the request, no task backend is connected, or the cache is per process. |
| The SMTP server accepts a connection and the login. No email is sent. With the email activity app installed, the row links to the sent emails and is degraded when any failed in the last 24 hours. | The email backend is not SMTP. | |
| Migrations | Every migration is applied. Unapplied migrations are degraded. | |
| Database backups | With the backups app installed: the latest backup is not overdue and did not fail. | BACKUP_SCHEDULE is None. |
| Error reports | Where error reports go: someone gets the emails, or Sentry has its DSN and SDK. | ERROR_REPORTS is "off" (no row), or DEBUG is on. |
Add a service
Register a service from your app's AppConfig.ready(). The check is a
function without arguments that returns status.ok(), status.degraded(),
status.down() or status.unknown().
# shop/apps.py
from django.apps import AppConfig
class ShopConfig(AppConfig):
name = "shop"
def ready(self):
from content_studio.contrib import status
from .payments import client
def check_payments():
seconds = client.ping()
if seconds > 1:
return status.degraded(
"Mollie API",
message=f"Responding slowly: {seconds:.1f} s.",
)
return status.ok("Mollie API")
status.register_service(
"shop.payments",
"Payment provider",
check_payments,
icon="ph-bold ph-credit-card",
)
register_service(key, label, check, icon=None, group=None, timeout=5, url=None):
key: lowercase dotted words that start with your app, such as"shop.payments".label: the name of the service on the page.check: the function. The first argument of its result is a short line about the service ("Mollie API");messagesays what is wrong. ReturningNonecounts as operational.icon: a Phosphor icon class.group: the heading the service is listed under. By default it is the name of the app the check is defined in.timeout: the seconds the check may take.url: makes the service's name a link, to a page of the admin ("backups") or to anhttp(s)address, which opens in a new tab.
A check that raises an exception, or does not answer within its timeout,
shows the service as down with the exception as its message. The checks run
side by side, so one slow service does not hold up the page.
Use status.unknown() when there is nothing to check, such as an
integration that is switched off. Services that are not checked do not count
toward the overall status.
Keep checks cheap and free of side effects: they run whenever a superuser opens the page. Do not send an email or charge a card to see whether it works.
Registering works without the status app in INSTALLED_APPS, so a reusable
app can register its services unconditionally. manage.py check reports a
malformed key, a check that is not callable and a key registered twice with
different definitions as content_studio.E047.
Tasks
The task lists come from a task adapter, the same class the task dashboard uses.
- With Huey installed (
huey.contrib.djhuey), the page shows its queue without any setup. Add Huey's stats app to see running and finished tasks. - For another backend, register your adapter:
# shop/apps.py, in ready()
status.register_task_adapter(CeleryAdapter())
A registered adapter replaces the automatic Huey one. Without an adapter, the page says that no task backend is connected.
The status page uses two adapter methods the task dashboard does not need:
get_pending_tasks(request, limit): the queued and running tasks, asTaskRowwith the statusTaskStatus.QUEUEDorTaskStatus.RUNNING.get_health(): aTaskHealth(status, detail, message)for the Task queue service, with the status"ok","degraded","down"or"unknown".
A TaskRow can also carry a key (the task's dotted path, such as
"shop.tasks.sync_orders"), a source (the app it belongs to, as shown)
and, for a periodic task, a schedule in words. From the key the page
names the task ("Sync orders") and its app. To choose the name yourself:
status.register_task("shop.tasks.sync_orders", "Sync orders with the shop")
The Huey adapter reports the queue as degraded when the first task in the queue has waited for more than five minutes and no worker picked anything up in that time, which usually means the consumer is not running. This needs Huey's stats app.
Recurring tasks
A task adapter's get_periodic_tasks() fills the list of recurring tasks.
register_recurring_task() describes one of them, or adds a job that no
task backend knows about, such as a cron job.
from content_studio.contrib import status
from .backups import last_backup, next_backup
status.register_recurring_task(
"backups.database",
"Back up the database",
"Every day at 02:00",
get_last_run=last_backup,
get_next_run=next_backup,
)
register_recurring_task(key, label, schedule="", get_last_run=None, get_next_run=None, group=None):
key: lowercase dotted words. When it is thekeyof a periodic task an adapter reports, the two show as one row with yourlabelandschedule.schedule: when the task runs, in words.get_last_run: a function that returns when the task last ran, as adatetime. Returnstatus.Run(at, ok=False, message="...")to say that the run failed.get_next_run: a function that returns when the task runs next. A task more than a minute past that time shows as due.group: where the task belongs, as shown. By default the app of the key.
Maintenance commands
The Maintenance card runs Content Studio's management commands from the page, so you do not need a shell on the server to make the image sizes again or clean up old data. Each row shows what the command does and its latest run: who started it, when, how long it took and whether it succeeded. After a run, Show output shows what the command printed.


| Command | What it does | Shown when |
|---|---|---|
| Make image sizes | Makes the image sizes that are missing or out of date and deletes sizes no longer configured. Tick Make every size again after changing a size's quality or format. Same as content_studio_image_sizes. | The media library is set up and IMAGE_SIZES has sizes. |
| Make thumbnails | Makes the thumbnails of images that have none. Same as content_studio_thumbnails. | The media library is set up and THUMBNAIL_FOLDER is set. |
| Read media metadata | Reads the width, height and file size of items that have no metadata. Same as content_studio_media_metadata. | The media library is set up. |
| Publish scheduled content | Records the content that went live or expired on schedule. Same as content_studio_publish. | Always. |
| Deliver webhooks | Sends the webhook deliveries that are due and retries failed ones. Same as content_studio_deliver_webhooks. | The webhooks app is installed. |
| Send notification digest | Emails editors the notifications they have not read. Same as content_studio_send_notification_digest. | The notifications app is installed and the digest is on. |
| Back up the database | Backs up every database in BACKUP_DATABASES, as Back up now on the Backups page does. | The backups app is installed. |
| Clean up old data | Deletes notifications, history versions, audit log entries, logged emails, expired draft links and unused uploads past their retention settings. | Always. |
Commands with choices, or that send email or delete data, open a dialog first. The dialog of Clean up old data has a box for each kind of data, with how many items it would delete right now, and a red button.
A run is a Django task. With a task backend that runs tasks in the background, such as Huey, the run is queued and you can leave the page; it also shows under Recent tasks. Without one, the command runs while the page waits for it. Making the sizes, thumbnails or metadata of a large media library can take longer than your server allows a request to take, so those dialogs then suggest running the command on the server instead.
A command runs once at a time: its button is off while a run is queued or running. A run that has not finished after six hours counts as failed, and the command can run again. Each command keeps its latest run, with the last 64 KB of its output.
Add a command
Register a management command, or a function, from your app's
AppConfig.ready():
# shop/apps.py
from django.apps import AppConfig
class ShopConfig(AppConfig):
name = "shop"
def ready(self):
from content_studio.contrib import status
status.register_command(
"shop.reindex",
"Rebuild the search index",
"shop_reindex",
description="Index every product again.",
options=[
status.CommandOption(
"full",
"Start from scratch",
help="Drop the index first. Search is empty until it is done.",
),
],
icon="ph-bold ph-magnifying-glass",
long_running=True,
)
register_command(key, label, command, description="", options=None, group=None, icon=None, confirm=None, destructive=False, long_running=False):
key: lowercase dotted words that start with your app.command: the name of a management command, run withcall_command()and the options chosen in the dialog, or a function that takes the options as keyword arguments and returns its output as text. An exception, such asCommandError, makes the run fail with its message.description: what the command does, under its name.options: the choices in its dialog, asCommandOption.group: the heading the command is listed under. By default it is the name of the app the command comes from.icon: a Phosphor icon class.confirm: open the dialog even when the command has no options. It does whenever there are options.destructive: for commands that delete data: the dialog's button is red.long_running: for commands that can take minutes: without a task backend in the background, the dialog warns that the run may time out.
CommandOption(name, label, help="", type="boolean", default=None, count=None):
name: the keyword the command takes: thedestof its argument,"full"for--full.type:"boolean"for a box or"integer"for a number of 0 or more.count: for a box, a function that returns how many items the option would affect now. The dialog shows the number next to the box.
manage.py check reports a malformed key or option, a key registered twice
with different definitions and a management command that does not exist as
content_studio.E047.
Who runs commands
Only superusers see and run the commands. Override
has_command_permission(request, command) on your admin site to decide per
command; command.key names it:
from content_studio.admin import ContentStudioSite
class BlogStudioSite(ContentStudioSite):
def has_status_permission(self, request):
return request.user.groups.filter(name="Operations").exists()
def has_command_permission(self, request, command):
if command.key == "content_studio.clean_up":
return request.user.is_superuser
return self.has_status_permission(request)
A command is only offered on the status page, so the viewer also needs
has_status_permission. Who started each run, and with which options, is
written to the content_studio.status logger.
Who sees the page
The service messages and task errors can reveal how your project works, so
only superusers see the page. Override has_status_permission(request) on
your admin site (ADMIN_SITE) to decide otherwise:
from content_studio.admin import ContentStudioSite
class BlogStudioSite(ContentStudioSite):
def has_status_permission(self, request):
return request.user.groups.filter(name="Operations").exists()
Users without the permission do not get the menu item, and the page's data is refused to them.