mirror of https://github.com/tiangolo/fastapi.git
107 lines
4.1 KiB
Markdown
107 lines
4.1 KiB
Markdown
# 🖥 📋
|
||
|
||
👆 💪 🔬 🖥 📋 🏃 *⏮️* 🛬 📨.
|
||
|
||
👉 ⚠ 🛠️ 👈 💪 🔨 ⏮️ 📨, ✋️ 👈 👩💻 🚫 🤙 ✔️ ⌛ 🛠️ 🏁 ⏭ 📨 📨.
|
||
|
||
👉 🔌, 🖼:
|
||
|
||
* 📧 📨 📨 ⏮️ 🎭 🎯:
|
||
* 🔗 📧 💽 & 📨 📧 😑 "🐌" (📚 🥈), 👆 💪 📨 📨 ▶️️ ↖️ & 📨 📧 📨 🖥.
|
||
* 🏭 💽:
|
||
* 🖼, ➡️ 💬 👆 📨 📁 👈 🔜 🚶 🔘 🐌 🛠️, 👆 💪 📨 📨 "🚫" (🇺🇸🔍 2️⃣0️⃣2️⃣) & 🛠️ ⚫️ 🖥.
|
||
|
||
## ⚙️ `BackgroundTasks`
|
||
|
||
🥇, 🗄 `BackgroundTasks` & 🔬 🔢 👆 *➡ 🛠️ 🔢* ⏮️ 🆎 📄 `BackgroundTasks`:
|
||
|
||
```Python hl_lines="1 13"
|
||
{!../../../docs_src/background_tasks/tutorial001.py!}
|
||
```
|
||
|
||
**FastAPI** 🔜 ✍ 🎚 🆎 `BackgroundTasks` 👆 & 🚶♀️ ⚫️ 👈 🔢.
|
||
|
||
## ✍ 📋 🔢
|
||
|
||
✍ 🔢 🏃 🖥 📋.
|
||
|
||
⚫️ 🐩 🔢 👈 💪 📨 🔢.
|
||
|
||
⚫️ 💪 `async def` ⚖️ 😐 `def` 🔢, **FastAPI** 🔜 💭 ❔ 🍵 ⚫️ ☑.
|
||
|
||
👉 💼, 📋 🔢 🔜 ✍ 📁 (⚖ 📨 📧).
|
||
|
||
& ✍ 🛠️ 🚫 ⚙️ `async` & `await`, 👥 🔬 🔢 ⏮️ 😐 `def`:
|
||
|
||
```Python hl_lines="6-9"
|
||
{!../../../docs_src/background_tasks/tutorial001.py!}
|
||
```
|
||
|
||
## 🚮 🖥 📋
|
||
|
||
🔘 👆 *➡ 🛠️ 🔢*, 🚶♀️ 👆 📋 🔢 *🖥 📋* 🎚 ⏮️ 👩🔬 `.add_task()`:
|
||
|
||
```Python hl_lines="14"
|
||
{!../../../docs_src/background_tasks/tutorial001.py!}
|
||
```
|
||
|
||
`.add_task()` 📨 ❌:
|
||
|
||
* 📋 🔢 🏃 🖥 (`write_notification`).
|
||
* 🙆 🔁 ❌ 👈 🔜 🚶♀️ 📋 🔢 ✔ (`email`).
|
||
* 🙆 🇨🇻 ❌ 👈 🔜 🚶♀️ 📋 🔢 (`message="some notification"`).
|
||
|
||
## 🔗 💉
|
||
|
||
⚙️ `BackgroundTasks` 👷 ⏮️ 🔗 💉 ⚙️, 👆 💪 📣 🔢 🆎 `BackgroundTasks` 💗 🎚: *➡ 🛠️ 🔢*, 🔗 (☑), 🎧-🔗, ♒️.
|
||
|
||
**FastAPI** 💭 ⚫️❔ 🔠 💼 & ❔ 🏤-⚙️ 🎏 🎚, 👈 🌐 🖥 📋 🔗 👯♂️ & 🏃 🖥 ⏮️:
|
||
|
||
//// tab | 🐍 3️⃣.6️⃣ & 🔛
|
||
|
||
```Python hl_lines="13 15 22 25"
|
||
{!> ../../../docs_src/background_tasks/tutorial002.py!}
|
||
```
|
||
|
||
////
|
||
|
||
//// tab | 🐍 3️⃣.1️⃣0️⃣ & 🔛
|
||
|
||
```Python hl_lines="11 13 20 23"
|
||
{!> ../../../docs_src/background_tasks/tutorial002_py310.py!}
|
||
```
|
||
|
||
////
|
||
|
||
👉 🖼, 📧 🔜 ✍ `log.txt` 📁 *⏮️* 📨 📨.
|
||
|
||
🚥 📤 🔢 📨, ⚫️ 🔜 ✍ 🕹 🖥 📋.
|
||
|
||
& ⤴️ ➕1️⃣ 🖥 📋 🏗 *➡ 🛠️ 🔢* 🔜 ✍ 📧 ⚙️ `email` ➡ 🔢.
|
||
|
||
## 📡 ℹ
|
||
|
||
🎓 `BackgroundTasks` 👟 🔗 ⚪️➡️ <a href="https://www.starlette.io/background/" class="external-link" target="_blank">`starlette.background`</a>.
|
||
|
||
⚫️ 🗄/🔌 🔗 🔘 FastAPI 👈 👆 💪 🗄 ⚫️ ⚪️➡️ `fastapi` & ❎ 😫 🗄 🎛 `BackgroundTask` (🍵 `s` 🔚) ⚪️➡️ `starlette.background`.
|
||
|
||
🕴 ⚙️ `BackgroundTasks` (& 🚫 `BackgroundTask`), ⚫️ ⤴️ 💪 ⚙️ ⚫️ *➡ 🛠️ 🔢* 🔢 & ✔️ **FastAPI** 🍵 🎂 👆, 💖 🕐❔ ⚙️ `Request` 🎚 🔗.
|
||
|
||
⚫️ 💪 ⚙️ `BackgroundTask` 😞 FastAPI, ✋️ 👆 ✔️ ✍ 🎚 👆 📟 & 📨 💃 `Response` 🔌 ⚫️.
|
||
|
||
👆 💪 👀 🌖 ℹ <a href="https://www.starlette.io/background/" class="external-link" target="_blank">💃 🛂 🩺 🖥 📋</a>.
|
||
|
||
## ⚠
|
||
|
||
🚥 👆 💪 🎭 🏋️ 🖥 📊 & 👆 🚫 🎯 💪 ⚫️ 🏃 🎏 🛠️ (🖼, 👆 🚫 💪 💰 💾, 🔢, ♒️), 👆 💪 💰 ⚪️➡️ ⚙️ 🎏 🦏 🧰 💖 <a href="https://docs.celeryq.dev" class="external-link" target="_blank">🥒</a>.
|
||
|
||
👫 😑 🚚 🌖 🏗 📳, 📧/👨🏭 📤 👨💼, 💖 ✳ ⚖️ ✳, ✋️ 👫 ✔ 👆 🏃 🖥 📋 💗 🛠️, & ✴️, 💗 💽.
|
||
|
||
👀 🖼, ✅ [🏗 🚂](../project-generation.md){.internal-link target=_blank}, 👫 🌐 🔌 🥒 ⏪ 📶.
|
||
|
||
✋️ 🚥 👆 💪 🔐 🔢 & 🎚 ⚪️➡️ 🎏 **FastAPI** 📱, ⚖️ 👆 💪 🎭 🤪 🖥 📋 (💖 📨 📧 📨), 👆 💪 🎯 ⚙️ `BackgroundTasks`.
|
||
|
||
## 🌃
|
||
|
||
🗄 & ⚙️ `BackgroundTasks` ⏮️ 🔢 *➡ 🛠️ 🔢* & 🔗 🚮 🖥 📋.
|