Browse Source

🎨 Auto format

pull/14599/head
pre-commit-ci-lite[bot] 7 months ago
committed by GitHub
parent
commit
cdf6693303
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      docs/en/docs/tutorial/background-tasks.md

6
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 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"`). * 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)**. 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. This is expected behavior, but it is easy to overlook when building production systems.
### Silent Failure Example ### Silent Failure Example { #silent-failure-example }
```python ```python
def send_email(email: str): def send_email(email: str):
# If this fails, the exception goes unnoticed # If this fails, the exception goes unnoticed
@ -65,7 +65,7 @@ async def notify(background_tasks: BackgroundTasks, email: str):
# Returns success even if email fails! # Returns success even if email fails!
``` ```
### Proper Error Handling ### Proper Error Handling { #proper-error-handling }
```python ```python
import logging import logging

Loading…
Cancel
Save