From 7c5cc6cb0586ed49e92c34f3bd577a0b457fbea2 Mon Sep 17 00:00:00 2001 From: sheldy <85823514+sheldygg@users.noreply.github.com> Date: Sun, 20 Oct 2024 20:16:40 +0200 Subject: [PATCH] Add in-progress tutorial to how-to section (#1859) * Add in-progress tutorial to how-to section * Update pre-commit config * chore: fix precommit --------- Co-authored-by: Nikita Pastukhov --- .pre-commit-config.yaml | 3 -- docs/docs/SUMMARY.md | 1 + docs/docs/en/howto/nats/in-progress.md | 39 ++++++++++++++++++++++++++ docs/docs/navigation_template.txt | 1 + 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 docs/docs/en/howto/nats/in-progress.md diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f2852886c6..e4cde3a9c5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,7 +38,6 @@ repos: stages: [pre-commit, pre-merge-commit, manual] entry: "scripts/lint-pre-commit.sh" language: python - language_version: python3.10 types: [python] require_serial: true verbose: true @@ -49,7 +48,6 @@ repos: name: Static analysis entry: "scripts/static-pre-commit.sh" language: python - language_version: python3.10 types: [python] require_serial: true verbose: true @@ -60,7 +58,6 @@ repos: name: Build docs entry: "scripts/build-docs-pre-commit.sh" language: python - language_version: python3.10 files: ^docs require_serial: true verbose: true diff --git a/docs/docs/SUMMARY.md b/docs/docs/SUMMARY.md index 86ff1025b7..c220597872 100644 --- a/docs/docs/SUMMARY.md +++ b/docs/docs/SUMMARY.md @@ -98,6 +98,7 @@ search: - [Message Information](nats/message.md) - [How-To](howto/nats/index.md) - [DynaConf](howto/nats/dynaconf.md) + - [In-Progess](howto/nats/in-progress.md) - [Redis](redis/index.md) - [Pub/Sub](redis/pubsub/index.md) - [Subscription](redis/pubsub/subscription.md) diff --git a/docs/docs/en/howto/nats/in-progress.md b/docs/docs/en/howto/nats/in-progress.md new file mode 100644 index 0000000000..82a402ad0b --- /dev/null +++ b/docs/docs/en/howto/nats/in-progress.md @@ -0,0 +1,39 @@ +--- +# 0.5 - API +# 2 - Release +# 3 - Contributing +# 5 - Template Page +# 10 - Default +search: + boost: 10 +--- + +# In-Progress sender + +Nats Jetstream uses the at least once principle, so the message will be delivered until it receives the ACK status (even if your handler takes a long time to process the message), so you can extend the message processing status with a request + +??? example "Full Example" + ```python linenums="1" + import asyncio + + from faststream import Depends, FastStream + from faststream.nats import NatsBroker, NatsMessage + + broker = NatsBroker() + app = FastStream(broker) + + async def progress_sender(message: NatsMessage): + async def in_progress_task(): + while True: + await asyncio.sleep(10.0) + await message.in_progress() + + task = asyncio.create_task(in_progress_task()) + yield + task.cancel() + + @broker.subscriber("test", dependencies=[Depends(progress_sender)]) + async def handler(): + await asyncio.sleep(20.0) + + ``` diff --git a/docs/docs/navigation_template.txt b/docs/docs/navigation_template.txt index e505d5a783..1a1420d7ca 100644 --- a/docs/docs/navigation_template.txt +++ b/docs/docs/navigation_template.txt @@ -98,6 +98,7 @@ search: - [Message Information](nats/message.md) - [How-To](howto/nats/index.md) - [DynaConf](howto/nats/dynaconf.md) + - [In-Progess](howto/nats/in-progress.md) - [Redis](redis/index.md) - [Pub/Sub](redis/pubsub/index.md) - [Subscription](redis/pubsub/subscription.md)