Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌐 Add Chinese translation for docs/zh/docs/tutorial/background-tasks.md #2464

Closed
wants to merge 2 commits into from

Conversation

maoyibo
Copy link
Contributor

@maoyibo maoyibo commented Dec 3, 2020

🌐 Add Chinese translation for Tutorial - Background Tasks

@maoyibo maoyibo mentioned this pull request Dec 3, 2020
@codecov
Copy link

codecov bot commented Dec 3, 2020

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (cf73051) 100.00% compared to head (0bfae0e) 100.00%.
Report is 1220 commits behind head on master.

❗ Current head 0bfae0e differs from pull request most recent head 8a138dc. Consider uploading reports for the commit 8a138dc to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##            master     #2464     +/-   ##
===========================================
  Coverage   100.00%   100.00%             
===========================================
  Files          540       242    -298     
  Lines        13969      7396   -6573     
===========================================
- Hits         13969      7396   -6573     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2020

📝 Docs preview for commit 0bfae0e at: https://5fc89cd8ca35a2df0239e078--fastapi.netlify.app

@tiangolo tiangolo added awaiting-review lang-all Translations lang-zh Chinese translations labels Dec 19, 2020
* 执行操作后发送的电子邮件通知:
* 由于连接到电子邮件服务器和发送电子邮件往往是 "慢" (几秒钟)的,你可以立即返回响应,并在后台发送电子邮件通知。
* 处理数据:
* 例如,假设您接收一个必须经过缓慢进程的文件,您可以返回一个 "accept" 响应(HTTP 202)并在后台处理它。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 例如,假设您接收一个必须经过缓慢进程的文件,您可以返回一个 "accept" 响应(HTTP 202)并在后台处理它。
* 例如,假设您接收一个必须经过缓慢进程的文件,您可以返回一个「已接受」响应(HTTP 202并在后台处理它。


## 使用 `BackgroundTasks`

首先,导入 `BackgroundTasks` 并且在 *路径操作函数* 中定义一个参数,类型声明为 `BackgroundTasks` 。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
首先,导入 `BackgroundTasks` 并且在 *路径操作函数* 中定义一个参数,类型声明为 `BackgroundTasks`
首先,导入 `BackgroundTasks` 并且在*路径操作函数*中定义一个参数,类型声明为 `BackgroundTasks`


它只是一个可以接收参数的标准函数。

它可以是一个 `async def` 或普通的 `def` 函数,**FastAPI**将知道如何正确处理它。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
它可以是一个 `async def` 或普通的 `def` 函数,**FastAPI**将知道如何正确处理它。
它可以是一个 `async def` 或普通的 `def` 函数,**FastAPI** 将知道如何正确处理它。


它可以是一个 `async def` 或普通的 `def` 函数,**FastAPI**将知道如何正确处理它。

在本例中,任务函数将写入文件(模拟发送电子邮件)。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
在本例中,任务函数将写入文件(模拟发送电子邮件)
在本例中,任务函数将写入文件模拟发送电子邮件


在本例中,任务函数将写入文件(模拟发送电子邮件)。

并且由于写操作不使用 `async` 和 `await`,我们用普通的 `def` 定义函数:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
并且由于写操作不使用 `async``await`,我们用普通的 `def` 定义函数:
并且由于写操作不使用 `async``await`,我们用普通的 `def` 定义函数


## 警告

如果你需要执行较重的后台计算,且不一定需要由相同的进程执行(例如,你不需要共享内存变量,等等),你可能会受益于使用其他更大的工具,像<a href="https://docs.celeryproject.org" class="external-link" target="_blank">Celery</a>。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
如果你需要执行较重的后台计算,且不一定需要由相同的进程执行(例如,你不需要共享内存变量,等等),你可能会受益于使用其他更大的工具,像<a href="https://docs.celeryproject.org" class="external-link" target="_blank">Celery</a>。
如果你需要执行繁重的后台计算,且不一定需要由同一进程执行(例如,你不需要共享内存、变量等),你可能会受益于使用其他更大型的工具,例如 <a href="https://docs.celeryproject.org" class="external-link" target="_blank">Celery</a>。


如果你需要执行较重的后台计算,且不一定需要由相同的进程执行(例如,你不需要共享内存变量,等等),你可能会受益于使用其他更大的工具,像<a href="https://docs.celeryproject.org" class="external-link" target="_blank">Celery</a>。

它们往往需要更复杂的配置,一个消息/任务队列管理器,如 RabbitMQ 或 Redis ,但它们允许你在多个进程中运行后台任务,特别是在多个服务器中。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
它们往往需要更复杂的配置,一个消息/任务队列管理器,如 RabbitMQ 或 Redis ,但它们允许你在多个进程中运行后台任务,特别是在多个服务器中。
它们往往需要更复杂的配置,一个消息/任务队列管理器,如 RabbitMQ 或 Redis,但它们允许你在多个进程中运行后台任务,特别是在多个服务器中。


它们往往需要更复杂的配置,一个消息/任务队列管理器,如 RabbitMQ 或 Redis ,但它们允许你在多个进程中运行后台任务,特别是在多个服务器中。

要查看示例,请检查[Project Generators](../project-generation.md){.internal-link target=_blank},它们都包含已经配置好的Celery。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
要查看示例,请检查[Project Generators](../project-generation.md){.internal-link target=_blank},它们都包含已经配置好的Celery
要查看示例,请检查 [Project Generators](../project-generation.md){.internal-link target=_blank},它们都包含已经配置好的 Celery


要查看示例,请检查[Project Generators](../project-generation.md){.internal-link target=_blank},它们都包含已经配置好的Celery。

但是如果你需要从相同的 FastAPI 应用中访问变量和对象,或者你需要执行小的后台任务(比如发送邮件通知),你可以简单地使用 `BackgroundTasks` 。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
但是如果你需要从相同的 FastAPI 应用中访问变量和对象,或者你需要执行小的后台任务(比如发送邮件通知),你可以简单地使用 `BackgroundTasks`
但是如果你需要在同一个 FastAPI 应用中访问变量和对象,或者需要执行小型的后台任务(比如发送邮件通知),那就可以简单地使用 `BackgroundTasks`


## 总结

导入,并在 *路径操作函数* 和依赖项的参数中使用 `BackgroundTasks` 来添加后台任务。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
导入,并在 *路径操作函数* 和依赖项的参数中使用 `BackgroundTasks` 来添加后台任务。
导入,并在*路径操作函数*和依赖项的参数中使用 `BackgroundTasks` 来添加后台任务。

@tiangolo tiangolo changed the title 🌐 Add Chinese translation for Tutorial - Background Tasks 🌐 Add Chinese translation for docs/zh/docs/tutorial/background-tasks.md Jun 26, 2023
@tiangolo
Copy link
Member

📝 Docs preview for commit 8a138dc at: https://6499c7e9da96dc0080f3f275--fastapi.netlify.app

@tiangolo
Copy link
Member

As this PR had requested changes to be applied but has been inactive for a while, it's now going to be closed. But if there's anyone interested, feel free to create a new PR.

@tiangolo tiangolo closed this Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants