Skip to content

Commit 2bbce18

Browse files
committed
docs: Add context api reference docs
1 parent 1f5e166 commit 2bbce18

6 files changed

Lines changed: 32 additions & 7 deletions

File tree

docs/api/context.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# `Context` class
2+
3+
This page documents the `Context` class of FluxQueue.
4+
5+
You can import the `Context` class from `fluxqueue`:
6+
7+
```python
8+
from fluxqueue import Context
9+
```
10+
11+
::: fluxqueue.Context

docs/api/fluxqueue.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,3 @@ from fluxqueue import FluxQueue
1010
```
1111

1212
::: fluxqueue.FluxQueue
13-
options:
14-
members: - task

docs/api/models.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Models
2+
3+
This page documents the models of FluxQueue.
4+
5+
::: fluxqueue.TaskMetadata

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Welcome to FluxQueue documentation. FluxQueue is a lightweight, resource-efficie
1515
- [Worker Setup](tutorial/worker.md) - Deploy and run workers
1616
- [How it Works](how-it-works/index.md) - Learn more about how FluxQueue actually works
1717
- [Examples](examples/index.md) - FluxQueue examples with **Flask**, **Django**, **FastAPI**
18+
- [Features](features/index.md) - Features of FluxQueue
1819
- [API Reference](api/index.md) - Complete API documentation
1920

2021
## What is FluxQueue?

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ nav:
8181
- API Reference:
8282
- api/index.md
8383
- api/fluxqueue.md
84+
- api/context.md
85+
- api/models.md
8486
- api/environment.md
8587
- About: about.md
8688
- Release Notes: release-notes.md

python/fluxqueue/client.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def task_with_context(
108108
part of the function's public signature - users calling the function do not need to provide it.
109109
110110
Parameters
111-
----------
111+
---
112112
`name`:
113113
Optional explicit task name. If not set, a name is derived from the
114114
function name.
@@ -120,10 +120,20 @@ def task_with_context(
120120
Maximum number of retries the worker will attempt for this task
121121
before treating it as dead.
122122
123-
Example
123+
Example: Subclassing Context for Database Resource Pooling
124124
---
125+
This example demonstrates how to use `thread_storage` to persist a
126+
SQLAlchemy engine across the lifetime of a worker thread. This pattern
127+
prevents the overhead of recreating database connection pools for
128+
every individual task execution.
125129
126130
```py
131+
from fluxqueue import FluxQueue, Context
132+
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker, AsyncSession
133+
from contextlib import asynccontextmanager
134+
135+
fluxqueue = FluxQueue()
136+
127137
class DbContext(Context):
128138
def __init__(self) -> None:
129139
super().__init__()
@@ -148,15 +158,13 @@ async def session_context(self):
148158
await session.rollback()
149159
raise
150160
151-
152161
@fluxqueue.task_with_context()
153162
async def create_user_task(ctx: DbContext, email: str, username: str):
154163
async with ctx.session_context() as db_session:
155164
user = User(email=email, username=username)
156165
db_session.add(user)
157166
158-
159-
await create_user_task
167+
await create_user_task(email, username)
160168
```
161169
"""
162170

0 commit comments

Comments
 (0)