Document task DB access and unify background task DB handling
This commit is contained in:
@@ -687,6 +687,15 @@ APScheduler 4.x (async mode) manages recurring background tasks.
|
||||
|
||||
---
|
||||
|
||||
## 7.1 Background Tasks and Database Access
|
||||
|
||||
- APScheduler jobs run outside FastAPI request/response scope and therefore cannot rely on ``Depends(get_db)``.
|
||||
- Background tasks must open their own application database connection via ``app.db.open_db`` and close it when the work completes.
|
||||
- Use a shared task helper (``app.tasks.db.task_db``) so every task follows the same async context manager pattern and avoids connection leaks.
|
||||
- This pattern is intentional: task code is structurally separate from request-handling dependencies and should not attempt to reuse request-scoped DB connections.
|
||||
|
||||
---
|
||||
|
||||
## 8. API Design
|
||||
|
||||
### 8.1 Conventions
|
||||
|
||||
Reference in New Issue
Block a user