From cdf6693303a7bc7c9ba7d0f75b5f734b097e6920 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Wed, 24 Dec 2025 21:57:05 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Auto=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/tutorial/background-tasks.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/en/docs/tutorial/background-tasks.md b/docs/en/docs/tutorial/background-tasks.md index c94ee2e566..bcb37915db 100644 --- a/docs/en/docs/tutorial/background-tasks.md +++ b/docs/en/docs/tutorial/background-tasks.md @@ -45,13 +45,13 @@ Inside of your *path operation function*, pass your task function to the *backgr * Any sequence of arguments that should be passed to the task function in order (`email`). * Any keyword arguments that should be passed to the task function (`message="some notification"`). -## Important: Exception Handling +## Important: Exception Handling { #important-exception-handling } Background tasks run **after** the response is sent. If an exception occurs in a background task, it won't affect the response (which already succeeded), and **the exception will not be propagated to the request handler and may go unnoticed unless explicitly handled (e.g. logging, retries, alerts)**. This is expected behavior, but it is easy to overlook when building production systems. -### Silent Failure Example +### Silent Failure Example { #silent-failure-example } ```python def send_email(email: str): # If this fails, the exception goes unnoticed @@ -61,11 +61,11 @@ def send_email(email: str): @app.post("/notify/") async def notify(background_tasks: BackgroundTasks, email: str): background_tasks.add_task(send_email, email) - return {"message": "Notification sent"} + return {"message": "Notification sent"} # Returns success even if email fails! ``` -### Proper Error Handling +### Proper Error Handling { #proper-error-handling } ```python import logging @@ -94,7 +94,7 @@ This example uses logging for simplicity. In production, you might also: !!! tip For production systems with complex background jobs, consider: - + - [Celery](https://docs.celeryq.dev) - Distributed task queue - [arq](https://arq-docs.helpmanual.io/) - Async task queue for Python - [Dramatiq](https://dramatiq.io/) - Fast and reliable task processing