@@ -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